The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Friendly URL | GET parameters lost Re: Friendly URL | GET parameters lost


Here’s what I do – a very similar approach:


# if the filename is a “real” file or directory, don’t rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# if not, take the entire URL + query string and append it to index.php.
RewriteRule ^.*$ index.php%{REQUEST_URI} [QSA,L]

In php, you can get the original path the user typed with `$_SERVER` (or, on some hosts, `$_SERVER`), and the query string with `$_SERVER` (or, simply use the `$_GET` superglobal like normal).

The difference between using `PATH_INFO` and `REQUEST_URI` (as @BenWalker suggests) is that the latter will return both the path info and the query string together (and there’s nothing wrong with that; I just find it less useful). `REQUEST_URI` will still be available to you regardless of how you rewrite the request.

# example: user typed “ string”

print $_SERVER;
# prints “/pretty/url?ugly=query%20string”

print $_SERVER;
# prints “/pretty/url”

print $_SERVER;
# prints “ugly=query%20string”

print $_GET;
# prints “query string”