301 redirect for entire folder including all files

I’m trying to redirect an entire sub-folder and all the files in it to my home page. So I have a folder called /OLD/ and want any request for a file in that folder to go to http://example.com

I’m not redirecting to the same file in a new location. I just want to direct all to the home page. So http://example.com/OLD/foo.html would not go to http://example.com/foo.html. It would just go to http://example.com

I’ve added the following line to my .htaccess

redirect 301 /OLD/ http://example.com

This works only for the base sub folder, but not individual files in it. So http://example.com/OLD/ gets redirected fine, but http://example.com/OLD/foo.htm doesn’t.

I’ve tried a few variations, but they don’t work:

redirect 301 ^/OLD/?(.*) http://example.com
redirect 301 ^/OLD/ http://example.com

Thanks for any help.

Ahhhrrrggg… You always find the answer right after you ask the question. :blush: This one works:

redirectMatch 301 ^/OLD/ http://example.com

This also works and it faster because it doesn’t need to fire up the regex engine:

Redirect /OLD/ [noparse]http://example.com/[/noparse]

:slight_smile:

But isn’t it a good idea to label the redirect as 301 for search engines?

And actually that doesn’t work (for me at least). Individual files in the sub folder don’t get stripped correctly. It redirects [B][noparse]http://example.com/OLD/foo.htm[/noparse][/B] to [B][noparse]http://example.comfoo.htm/[/noparse][/B]

Using the example at http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect:

Redirect 301 /OLD http://example.com/

(although the redirection may not need the trailing /).

Regards,

DK

That also doesn’t work. http://example.com/OLD/foo.htm redirects to http://example.com/foo.htm

Anyway, I show the code that worked in my 2nd post above. Thanks for the other suggestions, but I have what works for me now.