Problem statement: I want to redirect only the home or main page only and at the same time do not want to redirect other pages like sub-domain URLs or Detailed or channel page.
Logic Behind:
First condition to check would be, check it is home URL.
Check it doesn’t have any query params

First check if redirection is enabled.
RewriteEngine On ## Check this line, it need to be available

####Redirect home URL
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://beta. [R=302,L,E=nocache:1]

We can also combined the above two rules into one.

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.$ [NC]
Rewriterule ^(.*)$ http://beta. [R=302,L,E=nocache:1]

####Redirect home URL based on continent.
To use geo info for redirection, verify following Mod_geo is enabled and following statement is available in .httaccess file.
GeoIPEnable On

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^ www.$ [NC]
Rewriterule ^(.*)$ http://beta. [R=302,L,E=nocache:1]

Now if we want to redirect based on country then we can use %{ENV:GEOIP_COUNTRY_CODE}

We can also place this code inside vhosts file.

Leave a Reply

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