homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

double 301

10+ Year Member

Msg#: 6305 posted 6:24 am on May 26, 2006 (gmt 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]



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

Msg#: 6305 posted 3:24 pm on May 26, 2006 (gmt 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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved