redirect domain name to www - mean-stack

i am doing one site(https://www.mazabhumirakshak.in).Below is my issue:when user enter only mazabhumirakshak.in in URL then entry should redirect directly to www.mazabhumirakshak.in in background.
I have created this site using Node,Mongo,express and Angular(MEAN stack).
Your help will be valuable for me.
Thanks,
Guru

on your Webserver you can crate a file .htaccess and
insert the following code
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L
Complete answer here
https://stackoverflow.com/a/12050652/7883023

Related

.htaccess allow embedding but redirect on direct image load

Right now I want to redirect users who open up a direct image thats embedded in another site.
livememe does this perfectly by having http://www.livememe.com/36opcf5.jpg redirect to http://www.livememe.com/36opcf5 even though the direct image url is embedded within another site.
Now I'm trying to acomplish the same thing and this is what I have so far:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?reddit.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?tumblr.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} ^$
RewriteRule ^i/([a-zA-Z0-9]+)\.(jpe?g|JPE?G)$ /r/$1 [R]
Now from what I understand is that I'm allowing these websites to embed my images in their site but I'm redirecting them if they access the url directly without being refered.
For example on my site I have images located like this: http://mysite.com/i/0b1be.JPG
While the article is located: http://mysite.com/r/0b1be
The redirect works but I'm still failing because you can still access the direct image if you followed it from any of the websites allowed.
You can try this code :
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?(reddit|tumblr|facebook|mysite).com/.*$ [NC]
RewriteRule ^i/([a-zA-Z0-9]+)\.(jpe?g|JPE?G)$ /r/$1 [R]
You could try to add this condition:
RewriteCond %{HTTP_ACCEPT} !^(.*)image(.*)$ [NC]

How to rewrite exact url while passing other paths through

I'm new to mod_rewrite, so I know this is probably a simple fix. I want to rewrite www.abc.com to www.xyz.com ONLY. I only want to do this in firefox. I do not want www.abc.com/def to redirect to www.xyz.com. Currently, I have the following:
RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]
RewriteCond %{HTTP_USER_AGENT} "firefox" [NC]
RewriteRule ^(.*)$ https://www.xyz.com [L,R=302]
I understand that the ^(.*)$ portion is what is allowing everything else to be redirected as well. What should I enter in there that will ONLY redirect www.abc.com?
Thank you!
Change the rule to
RewriteRule ^/?$ https://www.xyz.com [L,R=302]

301 Redirect Dynamic HOST includes DOCUMENT_ROOT

Based on what I read on Apache I used the following example they provided to do a 301 Redirect on all my web sites.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
This is not quite working as they said it would. If I try www.domain.com it works. If I try domain.com I get www.domain.com//home/www/public_html/www.domain.com
Looks like it wants to include the DOCUMENT_ROOT in the redirect. Am I better off to create an individual .htaccess for each web site?
What is faster to run - Apache or HTACCESS?
Try this instead. Make sure you include the RewriteBase /
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you still get the old result, your previous 301 redirect is probably cached, retest in Private (Incognito) Browsing Mode.
Using Apaches httpd.conf is faster since accessing the .htaccess file adds a small overhead—Apache checks every directory—and parent directory—for the file and it will be loaded for every request.
Using the httpd.conf is better when you have access to it. Use .htaccess if you don't have access to the main configuration file.

.htaccess redirect www to non-www url doesn't not apply on the other link than the index

I've a Mac server and everything working fine
I'm running a wordpress and have .htaccess to rewrite the rule for custom link and so on
right now I'm having a trouble once I visit my site
http://www.mysite.com/anypage.html This doesn't work and give me page not found error
but if I visit same page but removed the www http://mysite.com/anypage.html this will work fine
So I thought I will make sure if this happen to all the pages and it was having the problem with all the pages except the home page so if I visit http://www.mysite.com or http://mysite.com neither one will work
I tried with many .htaccess rewrite rules and non of them word
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^www\.(.*)$ http://$1 [L,R=301]
Please suggest what is the problem.
Thanks
All your www will be redirected to now www URLs.
Just do this and try:
RewriteCond %{HTTP_HOST} ^www\.(mysite\.com)/?$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L]

rewrite subdomain to domain

I have a request that would look something like this http://cariers.example.com/style/all.css that would need to be rewritten to http://www.example.com/style/all.css. The request could be anything from a file like .css or .js to an actual page .aspx.
Thanks for your help
Give this a try (for ISAPI_Rewrite 3):
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ [NC]
RewriteRule ^(.*\.(?:css|js|aspx))$ http://www.example.com/$1 [NC,L]

Resources