加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – RewriteRule不能使用加号(或*)字符

发布时间:2020-12-14 02:30:26 所属栏目:百科 来源:网络整理
导读:RewriteRule ^([a-z]).php$ /index.php?zig=$1 [NC,L] # working 此规则正常运行.但 RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working 要么 RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working 不管用.差异是().如何在
RewriteRule ^([a-z]).php$ /index.php?zig=$1 [NC,L] # working

此规则正常运行.但

RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working

要么

RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L] # not working

不管用.差异是().如何在上面的代码中使用?

这条规则很好:
RewriteRule ^([a-z]+).php$ /index.php?zig=$1 [NC,L]

但是会创建一个无限循环,因为重写的URI /index.php也匹配正则表达式模式.为了防止这种情况,您需要进行一些更改,例如阻止文件/目录进行此重写并转义点,因为它是一个特殊的正则表达式元字符:

# 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(查询字符串追加)标志在添加新查询参数时保留现有查询参数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读