Home > Software design >  301 Redirecting the domain if the page doesn't contain query string
301 Redirecting the domain if the page doesn't contain query string

Time:02-17

I only want to redirect the root page from 1 subdomain domain to another e.g: from https://checkout.example.com to https://www.example.com/index.php?route=checkout/cart/

however, all other pages and query strings with $ and & should remain untouched. e.g: https://checkout.example.com/?Amount=1899&Invoice=55498213 should remain as it is

I tried multiple htaccess rules texts: Redirect 301, Redirect, RedirectMatch, RewriteRule. All the rules are redirecting the domain with the query strings.

Here is my current .htaccess rule

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$
RewriteCond %{HTTP_HOST} ^checkout\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/index.php?route=checkout/cart/ [L,R=301]
</IfModule>

CodePudding user response:

This should work for you :

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^checkout\.domain1\.com$ [NC]
RewriteRule .* https://www.domain2.com/checkout [L,R=301]

CodePudding user response:

This finally works, Added to the top of .htaccess file

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^checkout\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/index.php?route=checkout/cart/ [L,R=301]
  • Related