apache - url 地址重写 如何去区分 ‘?’ 问号

【字号: 日期:2022-07-30浏览:71作者:雯心

问题描述

地址:http://localhost/aaa/bbb-ccc=222

RewriteRule ^([a-z,/,_,0-9]*)-(.*)$ index.php?routeeee=$1&$2 [L]

当用 ‘-’ 去区分地址URL时 数据都可以获取到,’-‘相当于一个分隔符

Array ( [routeeee] => aaa/bbb [ccc] =>222 )

当url地址中的‘-‘ 换成’?‘ 时就无法获取数据RewriteRule ^([a-z,/,_,0-9]*)?(.*)$ index.php?routeeee=$1&$2 [L]http://localhost/aaa/bbb?ccc=222

Array ( [routeeee] => index [_php] => )

RewriteRule ^([a-z,/,_,0-9]*)?(.*)$ index.php?routeeee=$1&$2 [L]这条规则该如何写 才能正常匹配 获取到正确的数据。

? 转义 ‘?’问号的话 就不匹配了

不胜感激

但是在nginx中这样是可以使用的

rewrite ^/(.)?(.)$ /index.php?route=$1&$2 last;这条规则在 nginx 是正常的。

问题解答

回答1:

apache 默认是忽视 querystring 的RewriteRule ^([a-z,/,_,0-9]*)$ index.php?route=$1& [L,QSA]

这样就OK了,强行执行时加上querystirng 好简单呀

相关文章: