.htaccess 将根目录重定向到子文件夹
我希望 mod_rewrite 将所有请求重定向到不存在的文件和文件夹,并将所有对主文件夹(“根”)的请求重定向到子文件夹。所以我是这样设置的:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
RewriteCond %{REQUEST_URI} / [NC]
RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]
不幸的是,它不起作用:如果我请求 example.com/public/ 它会重定向到我的处理脚本(因此重定向到 my/subfolder/index.php?app=public )文件夹“public”存在。 请注意,请求domain.com/正确地重定向到my/subfolder/index.php
这是为什么?
I would like mod_rewrite to redirect all requests to non existing files and folders, and all requests to the main folder ("root") to a subfolder. So i've set it up like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
RewriteCond %{REQUEST_URI} / [NC]
RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]
Unfortunately, it does not work: if i request example.com/public/ it redirects to my processing script (so redirecting to my/subfolder/index.php?app=public ) although the folder "public" exists.
Note that requesting domain.com/ correctly redirects to my/subfolder/index.php
Why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为你的最后一个条件不仅匹配根,还匹配任何包含 / 的 uri,这基本上就是一切。请尝试以下操作:
请注意,不需要 [NC],因为您不尝试匹配任何字母,因此实际上并不需要“无大小写”。
希望有帮助。
it does not work because your last condition is not matching only the root but any uri that has / in it, which is basically everything. Try the following instead:
Note that [NC] is not needed as you are not trying to match any alphabets, so "No Case" is not really needed.
Hope it helps.