So basically I want everyone who asks example.com/index.php to get 301 redirected to example.com/,
everyone who asks for any www. urls to get 301 redirected to corresponding non-www site
(www.examle.com/foo -> example.com/foo)
and everyone who asks for site with double [also triple etc.] slashes in url to get 301
redirected to url with double slashes remowed (example.com////foo -> example.com).
And if anyone should do any combination of these three cases, he should still get 301 redirected to right url (www.example.com////index.php -> example.com).
So I come up with that:
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]
BUT, http://www.example.com//foo -> http://example.com/http:/example.com/foo = 404!
How to get it working?
Screw logic, seriously…
I found out, that folloving stuff in .htaccess does proper (almoust, with little quirks) 301 redirects to right places…
…at the top, and the rewrite rules themselves:
I swear that these are only rewrite rules in my .htaccess.
The quirk is, that http://www.example.com//foo redirects(301) to example.com/foo, and then example.com/foo redirects(301) again to example.com/foo, bot only once… (no loops)
http://www.example.com//foo -> example.com/foo -> example.com/foo
Also when www and any other condition is met, redirection happens in steps:
http://www.example.com/index.php -> example.com/index.php -> example.com/
http://www.example.com//index.php -> example.com/index.php -> example.com/
But that’s not really big problem…