Here are the rules:
RewriteRule ^two$ show.php?id=1
So what is the output when you go to : two?id=2
$_GET['id']
equals 1 or 2?
I run the script, the answer is 1. But I don't understand why? Can anyone explain this to me?
Here are the rules:
RewriteRule ^two$ show.php?id=1
So what is the output when you go to : two?id=2
$_GET['id']
equals 1 or 2?
I run the script, the answer is 1. But I don't understand why? Can anyone explain this to me?
Apache ignores URL parameters for RewriteRule:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string.
If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
Therefore two?id=2
is matched by your rule as the URL is ^two$
and so is set to show.php?id=1
and note that the existing query string is replaced when a new one is given as per above link:
Modifying the Query String By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.