301 redirect

自古美人都是妖i 提交于 2019-12-02 03:55:46
Kent Fredric

See also: Hidden features of mod_rewrite

#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, example case 1, as said by Greg, will always put the / on if it is without a uri.

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

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

you could use a general rule that works on every domain without having to change the name of the domain all the time. This is very helpful when you have multiple domains parked on 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]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!