开发者

How do I redirect a subdirectory and all files in it to the root using htaccess?

开发者 https://www.devze.com 2023-01-09 01:44 出处:网络
I\'m trying t开发者_运维问答o 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 r

I'm trying t开发者_运维问答o 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消