views:

30

answers:

1

I'm trying to redirect all requests for a subdirectory and any files in it to the root directory, using htaccess. Currently I have redirect 301 /directory/ / But this redirects to the root with the file name requested appended to it.. ie www.domain.com/directory/this.html redirects to www.domain.com/this.html I don't want it to request the file at all. Is there a way to do this?

Thank you

Karl

+3  A: 

You will probably have to use mod_rewrite. Assuming you place the .htaccess in the root directory, something like this should work.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^name-of-subfolder/.*$ / [R=302]
</IfModule>

NB. I put 302, as it's always sensible to use for testing, 301 can make it a pain checking changes with your browser. Once it's working feel free to change to 302.

Cags
That worked perfectly.. Thank you so much.. I was trying to use the same syntax with redirectMatch, but it didn't work so well, as a matter of fact it stopped redirecting anything to the root. Again, Thank you Cags
Karl
@Karl - so did that solve it for you? Make sure to accept it so others know ;)
MisterPhilip
@MisterPhilip Yes, It did solve it.. Sorry, I didn't realize the checkmark was changeable. =)
Karl