By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Missing URL GET Parameters when using mod_rewrite

How to avoid inaccessible GET Parameters when using mod_rewrite on your website.

Edited: 2015-06-12 20:32

There is a problem with mod_rewrite which will make the query string inaccessible. This can however be easily solved by using the QSA modifier at the end of your rewrite rule – QSA stands for Query string append, and the query string is the part after the question mark in a URL.

In PHP the variables from the query string, also known as get variables, will normally be accessible from the $_GET superglobal. But due to this problem the get variables will be missing.

The solution is to include the QSA modifier in your rewrite rules, an example of how to do that can be seen below:

RewriteEngine on
RewriteRule ^([A-Za-z0-9\-]+)$ /?page=$1 [QSA,L]

The first line enables the Rewrite engine – there should be no need to explain that here. The second line is the actual Rewrite Rule. Sometimes the L modifier will be used alone, but that will effectively strip request parameters from the URL.

See also

  1. How to disallow URL parameters in PHP