Skip to main content
htaccess

How to remove the query string in a RewriteRule

By November 5, 2013January 7th, 2020No Comments

Sometimes you are trying to redirect a url http://example.com?id=5 to http://example.com/somepage using Apache mod_rewrite.

The easiest method we have found is to add the ? at the end of your RewriteRule destination URL

For Example:

 

RewriteCond %{QUERY_STRING} ^id=5$
 RewriteRule ^/$ /somepage? [R=301, L]

 

Thats pretty much it, the new destination URL will be free of the query string.

A cool online .htaccess testing tools we found helpful and think might help others figure out what is working and more importantly what is not working when creating an htaccess rule. Give i a try here http://htaccess.madewithlove.be/

The .htaccess testing does not work for all rules but it really is handy.

Leave a Reply