Rewriting URL that contains question mark(重写包含问号的 URL)
问题描述
我遇到了有关 URL 重写的问题.我正在使用 Apache 的 mod rewrite 来重写 URL.比如我改写网址
I am encountering a problem regarding URL rewriting. I am using Apache's mod rewrite to rewrite URLs. For example, I rewrite URL
www.website.com/some/path/到request.php?string=some/path/.
然后我显示此 URL 的特定响应.现在我的重写规则是这样的:
Then I show specific response for this URL. Right now my rewrite rule looks like this:
RewriteRule ^([a-z_/?]+)$ request.php?string=$1
但是如果我有 URL www.website.com/some/data/?id=12&name=John 并重写它,问题就会开始,我得到这样的东西:request.php?string=some/data/?id=12&name=John.在这个例子中,另一个问号似乎混淆了 PHP.如果我尝试在 request.php 中检索 $_GET['string'],我得到的只是:some/data/.
But the problem begins if I have URL www.website.com/some/data/?id=12&name=John and rewrite it, I get something like this: request.php?string=some/data/?id=12&name=John. It seems that in this example another question mark confuses PHP. If I try to retrieve $_GET['string'] in request.php all I get is: some/data/.
为了进一步参考,Gmail 对其网址做了类似的处理:https://mail.google.com/mail/?ui=1&shva=1
For further reference, Gmail does something similar with it's URL:
https://mail.google.com/mail/?ui=1&shva=1
推荐答案
我建议(作为 mario)查看 QSA 标志(查询字符串附加).另外,我会从正则表达式中的字符类中去掉问号:
I suggest (as mario) to take a look into the QSA flag (Query String Append). Additionally I would take the question-mark out of the character class in the regex:
RewriteRule ^([a-z_/]+)$ request.php?string=$1 [L,QSA]
这篇关于重写包含问号的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:重写包含问号的 URL
基础教程推荐
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
