问题
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