在.htaccess中使用多次重写删除重复内容

在.htaccess中使用多次重写删除重复内容,.htaccess,url-rewriting,.htaccess,Url Rewriting,因此,基本上我希望每个询问example.com/index.php的人都能将301重定向到example.com/, 要求任何www.url获得301重定向到相应非www站点的每个人 (www.examle.com/foo->example.com/foo) 每个要求在url中使用双斜杠[还有三重斜杠等]的人都可以获得301 已重定向到删除了双斜杠的url(example.com///foo->example.com) 如果有人同时使用这三种情况,他仍然应该将301重定向到正确的url(www

因此,基本上我希望每个询问example.com/index.php的人都能将301重定向到example.com/,
要求任何www.url获得301重定向到相应非www站点的每个人
(www.examle.com/foo->example.com/foo)
每个要求在url中使用双斜杠[还有三重斜杠等]的人都可以获得301
已重定向到删除了双斜杠的url(example.com///foo->example.com)

如果有人同时使用这三种情况,他仍然应该将301重定向到正确的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->=404

如何让它工作?

试试以下几行:

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]

搞砸逻辑,说真的

我发现,.htaccess中的以下内容确实正确(几乎没有,有点奇怪)301重定向到正确的位置

RewriteBase /
RewriteEngine on
…在顶部,以及重写规则本身:

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和任何其他条件时,重定向将分步骤进行:
www.example.com/index.php->example.com/index.php->example.com/
www.example.com//index.php->example.com/index.php->example.com/


但这并不是什么大问题……

不,不起作用。。。只要url中有index.php,它就会导致无限循环或类似的情况,无论如何服务器不会发送任何数据…它的工作原理与我回答的代码相同,具有相同的怪癖,但我的代码更短,更奇怪;D