Redirecting a domain to a website with a query string

 

A permanent 301 redirect in the  .htaccess file lets search engines know that an old link has been replaced by a new one. It’s the recommended method for directing traffic from an existing page.

Some common uses of a 301 .htaccess redirect to a new website with a query string:


 

  1. wildcard redirection
    OLDDOMAIN.COM/XXX.php?YYY -> NEWDOMAIN.COM/XXX.php?YYY
    (old webiste to new website , old query to the same query at the new website)

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]

 

  • Domain to new website with a predefined query string
    OLDDOMAIN.COM -> NEWDOMAIN.COM/page.php?a=5&b=6

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
    RewriteRule ^/?$ "http\:\/\/www\.newdomain\.com\/page\.php\?a\=5\&b\=6" [R=301,L]

 

  • Old website page to new website with a predefined query string
    OLDDOMAIN.COM/page.php -> NEWDOMAIN.COM/page.php?a=5&b=6

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
    RewriteRule ^page\.php$ "http\:\/\/www\.newdomain\.com\/page\.php\?a\=5\&b\=6" [R=301,L]

 

  • wildcard redirection to  new website + predefined querystring
    OLDDOMAIN.COM/anything  -> NEWDOMAIN.COM/page.php?a=5&b=6

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.com\/page\.php\?a\=5\&b\=6\&$1" [R=301,L]