简体   繁体   English

mod_rewrite重定向到文件夹

[英]mod_rewrite redirect to folder

I've read many posts on this subject, but for some reason none of code seems to work. 我已经阅读了许多有关此主题的文章,但由于某种原因,似乎没有任何代码有效。 If I have a domain example.com , I would like to redirect it to example.com/folder without the user knowing about the redirection. 如果我有一个example.com域,我想在用户不知道重定向的情况下将其重定向到example.com/folder

# file: public_html/.htaccess
RewriteEngine On
RewriteRule ^/(.*)$ /folder/$1 [L]

But it doesn't send me to folder . 但这并不会把我发送到folder Could someone tell me what I'm doing wrong. 有人可以告诉我我在做什么错。

Thanks 谢谢

Remove leading slash and include a negative lookahead: 删除前导斜杠并添加负前瞻:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+folder/ [NC]
RewriteRule ^ - [R=404,L]

RewriteRule ^((?!folder/).*)$ /folder/$1 [L,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM