所以基本上我希望每个请求example.com/index.php的人都能获得301重定向到example.com/,
每一个要求任何www的人。获得301重定向到相应的非www站点的urls
(网址:www.examle.com/foo -> example.com/foo)
和每个人谁要求的网站与双倍,也三重等,在url斜杠得到301
已重定向至删除了双斜杠的url (Example.com/foo -> example.com)。
如果任何人做了这三种情况的任何组合,他仍然应该得到301重定向到right url (www.example.com/index.php -> example.com)。
所以我想出了这个:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,N]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^(.*)$ /$1 [R=301]但是,www.example.com//foo -> http://example.com/http:/example.com/foo = 404!
如何让它正常工作?
发布于 2012-08-20 16:12:18
去他妈的逻辑,说真的..。
我发现,.htaccess中喜欢文件夹的东西可以正确地(当然,有一些小问题) 301重定向到正确的地方……
RewriteBase /
RewriteEngine on...at顶部,以及重写规则本身:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301]
RewriteRule ^index\.php$ / [QSA,R=301]我发誓这些只是我.htaccess中的重写规则。
奇怪的是,www.example.com//foo将(301)重定向到example.com/foo,然后example.com/foo再次重定向(301)到example.com/foo,bot只重定向一次...(无循环)
Www.example.com/foo -> example.com/foo -> example.com/foo
此外,当满足www和任何其他条件时,重定向将按步骤进行:
-> example.com/index.php -> example.com/
-> example.com/index.php -> example.com/
但这并不是什么大问题……
发布于 2012-08-20 04:49:03
试试下面这几行:
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301]
RewriteRule ^index.php$ / [L,QSA,R=301]
RewriteRule ^(.*)/{2,}(.*)$ /$1/$2 [L,N,QSA,R=301]https://stackoverflow.com/questions/12027506
复制相似问题