Welcome to WebmasterWorld Guest from 54.161.187.250

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewriting & redirecting directory name

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

10+ Year Member



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?

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

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



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

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

10+ Year Member



Awesome - thanks!