apache - url 地址重写 如何去区分 ‘?’ 问号
ringa_lee
ringa_lee 2017-05-16 17:04:10
[Linux讨论组]

地址: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 是正常的。

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
淡淡烟草味

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

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号