How to pass GET parameters to rewritten URL?
72,663
You are looking for the Q
uery S
tring A
ppend flag - e.g.
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^search/(.*)$ search.php?q=$1 [QSA]
See the mod_rewrite
documentation for a full description of RewriteRule flags.
Related videos on Youtube
Author by
Christopher
Updated on September 18, 2022Comments
-
Christopher over 1 year
I have an
.htaccess
rewrite rule like this:RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^search/(.*)$ search.php?q=$1
What this does is, if someone visits
http://example.com/search/test
the URI that is really processed ishttp://www.example.com/search.php?q=test
.Now, if I try to pass an extra random GET parameter to my rewritten URL, the parameter is ignored. So if I try to do visit here:
http://www.example.com/search/whatever?extra=true
The parameter
extra
is ignored. It doesn't seem to get passed at all.Can this problem be fixed? If so, how?
-
Christopher over 12 yearsAh nice! I knew there was something like that. I'm a
.htaccess
noob. -
Johneh over 9 yearsIs there a way to add QSA to all rules
-
Danny22 over 8 yearsHi @danlefree Know it's an old question, but using Wamp, when i do this, all my stylesheets, scripts etc lose reference. how can I solve that?