Search code examples
.htaccesshttp-redirectmod-rewrite

Redirecting a Domain with a Get Variable to a New Domain with the htaccess file


I am trying to send /bn/referral.php?id=xxxxx to https://www.newdomain.com/index.php?referral=xxxxx

I have it currently set up like this, with no luck:

RewriteRule ^/bn/referral.php?id=([0-9]+)$ https://www.newdomain.com/index.php?referral=$1 [NC,L]

Thanks in advance for any insight to this issue.


Solution

  • With your shown samples, attempts please try following .htaccess rules. Please make sure to clear your browser cache before testing your URLs. Also I am using here THE_REQUEST variable to handle both uri and query string together.

    RewriteEngine ON
    RewriteCond %{THE_REQUEST} \s/bn/(referral)\.php\?id=(\S+)\s [NC]
    RewriteRule ^ https://www.newdomain.com/index.php?%1=%2 [R=301,L]