oldford
November 15, 2010, 7:26pm
1
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.
oldford
November 15, 2010, 7:33pm
2
Ahhhrrrggg… You always find the answer right after you ask the question. This one works:
redirectMatch 301 ^/OLD/ http://example.com
rpkamp
November 15, 2010, 7:40pm
3
This also works and it faster because it doesn’t need to fire up the regex engine:
Redirect /OLD/ [noparse]http://example.com/[/noparse]
oldford
November 15, 2010, 7:57pm
4
But isn’t it a good idea to label the redirect as 301 for search engines?
oldford
November 15, 2010, 8:00pm
5
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]
dklynn
November 16, 2010, 10:07am
6
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
oldford
November 16, 2010, 2:27pm
7
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.