重写包含问号的网址 [英] Rewriting URL that contains question mark

查看:112
本文介绍了重写包含问号的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了有关URL重写的问题。我使用Apache的mod重写来重写URL。例如,我重写了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 /

  • www.website.com/some/path/ to
  • 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&安培;名称=约翰。看来在这个例子中,另一个问号混淆了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

推荐答案

查看 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]

这篇关于重写包含问号的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆