regex.htaccessmod-rewriteisapi-rewriteisapi-redirect

Best way to redirect from one site to new site adding a querystring to it


I am trying to redirect with .htaccess from one site to another.

However I want to add a querystring to the end of the URL that the redirect takes the person to. I have read lots of articles on here and they are about passing the querystring along to the new site, I just want to ADD a querystring (a promo code) to the rule.

Something like:

    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteCond %{HTTP_HOST} site.com$ [OR]
       RewriteCond %{HTTP_HOST} ^www.site.com$
       RewriteRule (.*)$ https://www.newsite.com/subscribe.aspx?code=xxke [R=301,L]
 </IfModule>

I have mod_rewrite enabled.

Any ideas


Solution

  • Since ":" and "?" may be special characters in format strings consider escaping them as follows:

    RewriteRule (.*)$ https\://www.newsite.com/subscribe.aspx\?code=xxke [R=301,L]