Parse question mark as normal character after mod_

2019-03-01 11:21发布

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!

2条回答
够拽才男人
2楼-- · 2019-03-01 11:38

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:

查看更多
可以哭但决不认输i
3楼-- · 2019-03-01 12:02

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]
查看更多
登录 后发表回答