Forum Moderators: phranque

Message Too Old, No Replies

Wildcard Redirect with .htaccess

Changing directory, want to redirect all requests to new location

         

MatthewHSE

6:01 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just posted this over in the Webmaster General forum, and it was suggested I bring it over here.

I need to rename one of my main directories. Obviously when I do this, visitor's bookmarks, and possibly some of my own internal links, will stop working. I want to redirect all requests for the old file location to the new locations. For example:

h*tp://mydomain.com/olddirectory/file.html

would be redirected to . . .

h*tp://mydomain.com/newdirectory/file.html

What with hundreds of files in that directory, I obviously don't want to create separate redirect rules for each file. Is there any way I can use .htaccess to create some sort of "wildcard" rule that will accomplish what I want? In other words, a .htaccess rule that will redirect all of the old directory files to the same file name in a new directory.

Thanks,

Matthew

jdMorgan

11:55 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matthew,

Sure, it's easy:


Redirect 301 /olddirectory http://mydomain.com/newdirectory

will redirect all requests which prefix-match on the left to the corresponding URL prefix on the right.

It's actually more difficult to *not* redirect all files - You have to use RedirectMatch to do that.

See Apache mod_alias [httpd.apache.org]

Jim