由网友(北岛孤鬼)分享简介:RewriteRule ^([a-z]).php$ /index.php?zig=$1 [NC,L] # working该规则是否正常工作。但This rule is working correctly. But RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,...
RewriteRule ^([a-z]).php$ /index.php?zig=$1 [NC,L] # working
该规则是否正常工作。但
This rule is working correctly. But
RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working
或
RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working
不工作。不同的是( +
)。如何使用 +
在code以上?
Is not working. Difference is (+
). How to use +
in the code above?
推荐答案
这条规则是好的:
RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L]
但会产生因为改写URI的无限循环的index.php
也匹配的正则表达式。为prevent这需要夫妻从此改写像preventing的文件/目录的变化和逃生点,因为它是一种特殊的正则表达式元字符:
but will create an infinite loop since rewritten URI /index.php
also matches the regex pattern. To prevent this you need couple of changes like preventing files/directories from this rewrite and escape the dot as it is a special regex meta character:
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]+).php$ index.php?zig=$1 [QSA,NC,L]
QSA
(查询字符串追加)标志preserves现有的查询参数,同时增加了新的。
QSA
(Query String Append) flag preserves existing query parameters while adding a new one.
相关推荐
最新文章