| trying to remove double slashes
|
nmjudy

msg:4013170 | 9:53 pm on Oct 25, 2009 (gmt 0) | I did a search on Webmasterworld for a solution on how to remove double slashes in the URL path string using mod rewrite. I copied and pasted what I thought to be the solution. I tested the new code using something similar to this: http://www.example.com/mydirectory//goodpages/ and I get an error from my server saying "redirect loop." Do I have something in the wrong order? Here is a copy of my .htaccess file: # Parse .html and .inc files for server-side includes AddHandler server-parsed .html .inc # # # Set up to enable mod_rewrite Options +FollowSymlinks +Includes All -Indexes RewriteEngine on # # # Redirect requests for index.html in any directory to "/" in the same directory RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+/)?index\.html\ HTTP RewriteRule ^(.+/)?index\.html$ http://www.example.com/$1 [R=301,L] # # # Redirect requests for index.htm in any directory to "/" in the same directory RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+/)?index\.htm\ HTTP RewriteRule ^(.+/)?index\.htm$ http://www.example.com/$1 [R=301,L] # # # Externally redirect to remove double slashes RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . http://www.example.com/%1/%2 [R=301,L] # # # Redirect requests for resources in non-www domains to same resources in www domain RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L]
|
jdMorgan

msg:4013210 | 11:29 pm on Oct 25, 2009 (gmt 0) | To be clear, are all of these rules 'new', or just the third one that was meant to address double-slashes? Jim
|
nmjudy

msg:4013213 | 11:37 pm on Oct 25, 2009 (gmt 0) | Earlier today I added the rewrite for index.htm (I didn't know how to combine it with index.html rewrite). Testing didn't generate any errors. Then I added the redirect to remove double slashes and it broke when I tested it with an URL with double slashes. All other redirects have been in place for a few years.
|
jdMorgan

msg:4013220 | 12:11 am on Oct 26, 2009 (gmt 0) | It looks like the problem is that your third rule does not take into account that %{REQUEST_URI} always starts with a slash, and so you are re-injecting a double slash at the beginning of "%1". Fixing that, making the same rule correct "two or more slashes," combining "html" and "htm" with a simple regular-expressions quantifier, and fixing a hole in and optimizing your domain canonicalization rule gives:
# Redirect requests for index.html or .htm in any directory to "/" in the same directory RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/ RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L] # # Externally redirect to remove double slashes RewriteCond %{REQUEST_URI} ^(/[^/]+/)/+(.*)$ [OR] RewriteCond %{REQUEST_URI} ^(/)/+(.*)$ RewriteRule ^. http://www.example.com%1%2 [R=301,L] # # Redirect non-canonical hostname requests to same resources in www subdomain RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Jim
|
|
|