Last Updated on April 12, 2021 by Amit

If you are getting a 500 internal server error for using QSD flag in your RewriteRule then its quite certain that your Apache version doesn’t support it. QSD is available on Apache 2.4+ versions. If your version is bellow the required lavel and you want to remove queryString from your URL then there is a nice workaround for you.
On Apache versions where QSD is not supported you can just use an empty question mark ? to trim queryString from your URLs. This trick works on all versions of Apache server.

Trim URL queryString with a question mark

Using a ? to remove queryString from URLs is a safe way to manipulate your URL queryStrings as it doesn’t return any server error and you can use it on all newer or older server versions .
The RewriteRule bellow removes queryStrings from the URL and redirects https://example.com/file.php?q=foo&n=bar to https://example.com/file.php .

RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=foo&n=bar$
RewriteRule ^file.php$ /file.php? [L,R]

Important thing to note in the rule above is the `?` and its location. The `?` must be at the end of destination path .

How useful was this post?

Click on a star to rate it!

Average rating 4.1 / 5. Vote count: 9

No votes so far! Be the first to rate this post.