I'm trying to code a custom rewrite rule for '.htaccess' file in my Apache webserver.
The main idea is to handle requests in the form:
example.com/foo
to 'index.php' file in the www_root:
example.com/index.php?queryString1=foo
As everyone knows, this is easy to do. Just by adding below lines to '.htaccess' file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-l
RewriteRule ^(.*)$ index.php?queryString1=$1 [QSA,L]
But the problem is that when we want to add another query string to the request, for example as follows:
example.com/foo?queryString2=bar&queryString3=baz
contrary to my expectations, the following URL does the same:
example.com/foo&queryString2=bar&queryString3=baz
I don't want the second case (in which second query string starts with '&') to be executed. Also, if you write in 'index.php' file:
<?php echo '<pre>'.print_r($_SERVER['QUERY_STRING'], TRUE).'</pre>'; ?>
then, the output of both URLs (example.com/foo?queryString2=bar&queryString3=baz and example.com/foo&queryString2=bar&queryString3=baz) will be unique:
queryString1=foo&queryString2=bar&queryString3=baz
Can anyone explain what's wrong with my codes in '.htaccess' file? Thanks.