Rewriting URL that contains question mark

我们两清 提交于 2019-12-02 11:51:53

问题


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/ to
  • request.php?string=some/path/.

Then I show specific response for this URL. Right now my rewrite rule looks like this:

RewriteRule ^([a-z_/\?]+)$ request.php?string=$1

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/.

For further reference, Gmail does something similar with it's URL:
https://mail.google.com/mail/?ui=1&shva=1


回答1:


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]


来源:https://stackoverflow.com/questions/10095704/rewriting-url-that-contains-question-mark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!