繁体   English   中英

htaccess-Rewriterule重定向到错误的URL

[英]htaccess - Rewriterule redirects to wrong URL

我有一个简单的重写:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA]

任何不存在的文件都应转发到index.php 但是,这里有一个目录images ,其中有七个图像,但没有index.php|html 当我打开localhost/images ,没有一个斜杠( localhost/images/正常工作),它会将我重定向到localhost/images/?p=images 我该怎么解决?

之所以发生这种情况,是因为mod_dir模块在mod_rewrite添加尾随斜杠到目录之后运行。 您应该添加一个条件以避免在规则中重写目录。 还使用重定向规则添加尾部斜杠:

RewriteEngine on

# add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]

暂无
暂无

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

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