Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule for Directory Name Changes

rewrite rule directory name change

         

asterix1

3:07 pm on May 2, 2006 (gmt 0)

10+ Year Member



Hello,

I do not understand regular expressions very well and am trying to find a rewrite rule that will allow me to redirect calls to old directories to new ones.

For example, Google currently has this page indexed:

domain.com/subdirectory-one/page

But "subdirectory-one" is now called "subdirectory-two," so I would like to redirect the above link to:

domain.com/subdirectory-two/page

I've gotten somewhat close with this, but the following appends the old subdirectory:

RewriteRule ^subdirectory-one.*$ [domain.com...] [R=301,L]

Result: domain.com/subdirectory-two/subdirectory-one/page

Any help is much appreciated!
Alex
<snip>

[edited by: jdMorgan at 1:32 pm (utc) on May 16, 2006]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

3:40 pm on May 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Re-read the mod_rewrite documentation [httpd.apache.org], and look for the term "back-reference."

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

The ability of several Apache modules to create back-references based on regular expressions provides a way to 'copy' parts of a URL or any other server variable for later use.

Jim

asterix1

3:52 pm on May 2, 2006 (gmt 0)

10+ Year Member



Wow - thanks for the lightning speed support :)

This works like a charm - thx!

I will read up on back references as well - thanks for the link.

Cheers,
Alex