Forum Moderators: phranque

Message Too Old, No Replies

Apache Rewrites.custom file Combine two rules / Avoid double slashes

Need help modifying existing Apache file to avoid getting double slashes

         

bamabydistance

4:00 pm on May 11, 2011 (gmt 0)

10+ Year Member



The following code is what is currently in use. The goal of the first piece of code is to redirect any traffic that reaches an "index.html" page of the site back to the root directory.

The second part redirects any traffic to "domainthatredirects.iw.edu" to "maindomain.iw.edu".

The redirects work fine but are leaving double slashes at the end of the domain name. For example, if I were to type in "domainthatredirect.iw.edu/directory1/ , it would redirect to "maindomain.iw.edu//directory1/

I'm somewhat familiar with regex but am not familiar enough to figure this one out.

RewriteCond %{THE_REQUEST} ^.*\/index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ "/$1" [R=301,L]

rewriteCond %{http_host} ^domainthatredirects\.iw\.edu$ [OR]
rewriteCond %{http_host} ^www.domainthatredirects\.iw\.edu$ [OR]
rewriteCond %{http_host} ^www.maindomain\.iw\.edu$ [NC]
rewriteRule ^(.*)$ http://maindomain\.iw\.edu/$1 [r=301,L]


Thanks to anyone who would like to lend a hand!

g1smd

7:30 pm on May 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



# Externally redirect only direct client requests for /index.php
# and /index.html and /index.htm to URL ending with slash.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://example.com/$1 [R=301,L]


# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems

RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]

bamabydistance

8:01 pm on May 11, 2011 (gmt 0)

10+ Year Member



Thanks. I applied the changes you suggested and I'm still getting a double slash. I'm wondering if another part of my code is causing it. Do you mind if I private message you with the full code?