重写规则不工作与加号(+或*)字符

编程入门 行业动态 更新时间:2024-10-25 09:36:22
本文介绍了重写规则不工作与加号(+或*)字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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.

更多推荐

重写规则不工作与加号(+或*)字符

本文发布于:2023-11-16 18:22:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加号   重写   字符   规则   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!