Forum Moderators: phranque

Message Too Old, No Replies

Help with double slashes and mod rewrite

My rewrite rules have double slashes - help!

         

djcronos

8:34 pm on Sep 13, 2007 (gmt 0)

10+ Year Member



Hi all,

I have a VirtualHost set up that has the servername of xyz.com and a bunch of ServerAliases. The goal of these rewrites I implemented was to redirect people from the other domains to the main one. I've implemented this and it's working, but I'm running into the problem of having double slashes.

I'm doing this directly in the VirtualHost container, and not in .htaccess.

Here's the rewrite code:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

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

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

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

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

RewriteCond %{HTTP_HOST} ^www.abcnet.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^abcnet.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

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

What do I need to change or add to remove the double slashes from happening?

Thanks in advance!

[edited by: jdMorgan at 10:03 pm (utc) on Sep. 13, 2007]
[edit reason] example.com [/edit]

sc112

8:55 pm on Sep 13, 2007 (gmt 0)

10+ Year Member



How about:

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

[edited by: jdMorgan at 10:01 pm (utc) on Sep. 13, 2007]
[edit reason] Fixed missing space [/edit]