.htaccess rewrite for URL parameters

Suppose you have a page at


but you want people or bots that access it to see this page instead:


By the way, this is not some constrained example – it is from a real production site where the owner has little control over the PHP code.

It took a bit of experimenting plus the help of this answer to arrive at the answer, which is add the following to your .htaccess file:

RewriteEngine on
RewriteCond %{QUERY_STRING} ab=38$
RewriteRule ^mypage.php mypage.php?%{QUERY_STRING}&cd=39

Hope this saves someone some time.

Leave a Reply

Your email address will not be published. Required fields are marked *