How to pass GET parameters to rewritten URL?

72,663

You are looking for the Query String Append 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.

Share:
72,663

Related videos on Youtube

Christopher
Author by

Christopher

Updated on September 18, 2022

Comments

  • Christopher
    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 is http://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
    Christopher over 12 years
    Ah nice! I knew there was something like that. I'm a .htaccess noob.
  • Johneh
    Johneh over 9 years
    Is there a way to add QSA to all rules
  • Danny22
    Danny22 over 8 years
    Hi @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?