homepage Welcome to WebmasterWorld Guest from 54.227.12.4
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewriting & redirecting directory name
siteseo




msg:1506417
 12:05 am on Feb 7, 2006 (gmt 0)

I want to rewrite and redirect users from
http://www.example.com/blue-widget/page.php
to
http://www.example.com/purple-widget/page.php

I've tried simple rewrite statements, RewriteCond %{REQUEST_URI} statements and RewriteCond %{THE_REQUEST} statements in various incarnations and can't seem to get any of them to work. The closest I've gotten is with this:
RewriteCond %{REQUEST_URI} /blue-widget/
RewriteRule ^(.*)$ http://www.example.com/purple-widget/$1 [R=301,L]

The result of the above is that /blue-widget/ gets appended to the end of the URL, so this:
http://www.example.com/blue-widget/
becomes this:
http://www.example.com/purple-widget/blue-widget/
And this:
http://www.example.com/blue-widget/page.php
becomes this:
http://www.example.com/purple-widget/blue-widget/page.php

I feel like I'm getting really close to a solution. Any help?

 

jdMorgan




msg:1506418
 12:18 am on Feb 7, 2006 (gmt 0)

If the code goes into the top-level directory .htaccess file, then it's:

RewriteRule ^blue-wdget/(.*)$ http://www.example.com/purple-widget/$1 [R=301,L]

Or you can put this code into the .htaccess file in the /blue-widget subdirectory:

RewriteRule ^(.*)$ http://www.example.com/purple-widget/$1 [R=301,L]

The URLs 'seen' by RewriteRule are localized to the current directory, which accounts for the difference.

Jim

siteseo




msg:1506419
 5:04 pm on Feb 7, 2006 (gmt 0)

Awesome - thanks!

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