Parse question mark as normal character after mod_rewrite

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:37:42

问题


So this may sound weird, however I currently have mod_rewrite set-up to pass 2 variables through.

RewriteRule ^profiel/(.*)$ index.php?p=profiel&user=$1

In the second var (&user=), it passes a username which is retrieved through GET in PHP. However, some of the usernames can have question marks in them. However if this is the case, the question mark won't be passed to the GET variable. (For example: "www.example.com/profiel/whoami?" ends up as just "whoami" instead of "whoami?")

I honestly don't know how to solve this problem. Any help would be great!


回答1:


You can use this rule by capturing your values directly from THE_REQUEST variable:

RewriteEngine On

RewriteCond %{THE_REQUEST} /(profiel)/(\S+)\s [NC]
RewriteRule ^profiel/ index.php?p=%1&user=%2 [L,NC]



回答2:


You can use the PHP function urlencode to encode the username. For example, whoami? will become whoami%3F. So your url will become www.example.com/profiel/whoami%3F

Then to retrieve your username, you can use urldecode.

Here's the documentation on both function:

  • urlencode
  • urldecode


来源:https://stackoverflow.com/questions/35658832/parse-question-mark-as-normal-character-after-mod-rewrite

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