+-
![正则表达式 – RewriteRule ^(.*)/ $?path = $1 [QSA,L]在我的.htaccess中意味着什么? 正则表达式 – RewriteRule ^(.*)/ $?path = $1 [QSA,L]在我的.htaccess中意味着什么?](/img/no_img.png)
我需要像在.htaccess中一样在nginx中创建重写,并且有一些我不完全理解的行.
DirectoryIndex index.php
RewriteEngine on
RewriteCond % !-f
RewriteRule ^(.*)/$?path=$1 [QSA,L]
有人可以向我解释一下吗?
最佳答案
RewriteCond%! – f似乎是不正确的规则条件,并且总是评估为true.
这条规则:
RewriteRule ^(.*)/$?path=$1 [QSA,L]
将任何URI与尾部斜杠匹配并在内部重写到/?path = uri-without-slash
所以对于ex:URI / foo /将被重写为/?path = foo
> QSA – 查询字符串追加
> L =最后一条规则
参考:Apache mod_rewrite Introduction
更新:将错误的条件更改为:
# request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
# request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$?path=$1 [QSA,L]
点击查看更多相关文章
转载注明原文:正则表达式 – RewriteRule ^(.*)/ $?path = $1 [QSA,L]在我的.htaccess中意味着什么? - 乐贴网