301 redirects

eg http://mydomain.com ---> http://www.mydomain.com

+1


source to share


3 answers


See also: Hidden mod_rewrite functions

#1
RewriteRule /index.php=HairThing$ http://www.mydomain.com [R=301]

#2
RewriteCond %{HTTP_HOST} ^mydomain.com 
RewriteRule .*   http://www.mydomain.com [R=301] 

      



However, the case 1 example, as Greg said, will always include /

if it has no uri.

mydomain.com  # impossible 
mydomain.com/ # possible
mydomain.com/foo  #possible
mydomain.com/foo/ #possible

      

+4


source


For your second question, the browser will always put a forward slash after the site name. This is because the trailing slash is required to indicate the root path of the website.



+2


source


you can use a general rule that works in every domain without having to change the domain name all the time. This is very useful if you have multiple domains parked on the same root.

RewriteCond %{HTTP_HOST}    !^www\.[a-z0-9-]+\.[a-z]{2,6}   [NC]
RewriteCond %{HTTP_HOST}    ([a-z0-9-]+\.[a-z]{2,6})$       [NC]
RewriteRule (.*)            http://www.%1/$1                [L,R=301]

      

0


source







All Articles