Answer the question
In order to leave comments, you need to log in
.htaccess, mod_rewrite and duplicate slashes?
Good afternoon, to remove duplicate slashes, I use a regular expression of the form:
RewriteCond %{REQUEST_URI} ^(.*?)/{2,}(.*?)$ [NC]
RewriteRule . %1/%2 [R=301]
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET ////WAT////no////u//must/be////kidding/////me// HTTP/1.1" 301 269
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no////u//must/be////kidding/////me// HTTP/1.1" 301 266
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no/u//must/be////kidding/////me// HTTP/1.1" 301 265
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no/u/must/be////kidding/////me// HTTP/1.1" 301 262
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no/u/must/be/kidding/////me// HTTP/1.1" 301 258
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no/u/must/be/kidding/me// HTTP/1.1" 301 257
127.0.0.1 - - [17/Jul/2013:12:23:04 +0300] "GET /WAT/no/u/must/be/kidding/me/ HTTP/1.1" 404 226
http://test.ru///////
, it is not caught by a rewrite, no matter how hard I try. In the upper case, these slashes are removed during the internal Apache redirect, but not by rewriting, this can be seen from the second line of the log, in which it is clear that the slashes disappeared not only at the beginning, but also before “no”, which was done by mod_rewrite.
Answer the question
In order to leave comments, you need to log in
2 years have passed. Catch the solution:
# Редирект на страницу без многократных /.
RewriteCond %{THE_REQUEST} //
RewriteRule .* /$0 [R=301,L]
Option without crutches:
RewriteCond %{REQUEST_URI} ^(.*?)/{2,}(.*?/{2,}.*?)$ [NC]
RewriteRule . %1/%2 [L]
RewriteCond %{REQUEST_URI} ^(.*?)/{2,}(.*?)$ [NC]
RewriteRule . %1/%2 [R=301]
I'm no expert, but try something like this:
RewriteRule ^Simplify/(.*?)/{2,}(.*?) Simplify/%1/%2 [N,C]
RewriteRule ^Simplify/(.*?) %1 [R=301,L]
RewriteRule ^(.*?)/{2,}(.*?) Simplify/%1/%2 [N]
As a crutch, I can suggest redirecting requests in which there are two slashes in a row to a script (without the "R" flag), which will already clean up the URL and issue the correct redirect.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question