Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

double 301

6:24 am on May 26, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 3, 2002
votes: 0

I am currently doing a non-www redirect using

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

Alas, some folks have set links to a subdirectory of mine using http*//example.com/bar , but the correct canonical URL would be http*//www.example.com/bar/
So, currently, there is a double redirect
1) http*//example.com/bar => http*//www.example.com/bar
2) http*//www.example.com/bar => http*//www.example.com/bar/

Any simple way to get a single 301?


[edited by: jdMorgan at 3:26 pm (utc) on May 26, 2006]
[edit reason] example.com [/edit]

3:24 pm on May 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

Sure, just fix /bar before the catch-all domain redirect:

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

Replace the broken pipe "¦" character with a solid pipe character before use.