PDA

View Full Version : .htaccess RedirectMatch


JWM
09-26-2001, 05:29 PM
I just got this to work, and I was so pleased with myself that just had to post this :D

I replaced a flat file link directory program that generated subdirectories and html files with a MySQL/PHP script.

I wanted to make sure that anyone who tried to access any of the various (99) subdirectories under the old directory were redirected to the new directory.

old directory = /dcd
new directory = /links

redirect /dcd http://www.myurl.com/links

worked, sort of. The problem was the sub-directories. If someone tried to access myurl.com/dcd/subdirectory the above would redirect them to http://www.myurl.com/links/subdirectory which , of course, didn't exist. :waa:

I didn't want to mess around with changing 99 files, or adding 99 .htaccess files, so I search around until I found a reference on the FQ forums to RedirectMatch

Now, I'm using this in my root directory's .htaccess file:

RedirectMatch permanent /dcd/* http://www.myurl.com/links

and all's right with the world :P

No rocket science here, and I'm sure it's all old hat to most of you, but I'm pleased as hell with myself about it. 8}

Cindy
03-14-2002, 10:02 AM
James, thanks for the tutorial. I couldn't figure out how to direct everything formerly in a folder to one file. Your explanation helped.
Cindy

Arthur
03-14-2002, 10:18 AM
Just a small addition - it's best if you put a trailing slash behind the URL, so instead of http://www.myurl.com/links, use http://www.myurl.com/links/. Otherwise you get two redirects.

(See: Alistapart (http://www.alistapart.com/stories/slashforward/))