cancel
Showing results for 
Search instead for 
Did you mean: 

Sub-domain redirect

Sub-domain redirect

Greetings,

 

We have a magento store mokshafashions.com and a subdoamin running an India specific store/website in.mokshafashions.com

 

Now, I want to redirect all customers originating in India to in.mokshafashions.com and all other customers to mokshafashions.com

 

We can handle this via redirects in .htaccess but we want to also make sure that mokshafashions.com or any other page like mokshafashions.com/example.html to redirect to in.mokshafashions.com/example.html when opening from India.

 

Similarly when opening the site from outside India, in.mokshafashions.com/example.html should be redirected to mokshafashions.com/example.html

 

Also, please do note that mokshafashions.com/admin should not get redirected at all.

 

Kindly help me out with the regular expressions or code snippet that is needed.

 

All help is much appreciated.

 

Best,

Vipul

1 REPLY 1

Re: Sub-domain redirect

The code that we are using is as follows - 

 

.htaccess

 

RewriteCond %{HTTP_HOST} .*in.mokshafashions\.com [NC]

RewriteRule .* - [E=MAGE_RUN_CODE:india]

RewriteRule .* - [E=MAGE_RUN_TYPE:website]

RewriteCond %{HTTP_HOST} ^mokshafashions.com [NC]

RewriteRule ^(.*)$ in.mokshafashions.com/$1 [R=301,L]

RewriteRule ^(.*)$ mokshafashions.com/$1$1 [L]

RewriteCond %{REQUEST_URI} !^/admin.* – –

 

index.php

 

<?php

define("GEOIP_DAT_FILE", $_SERVER['DOCUMENT_ROOT'] . "/geoip/GeoIP.dat");

define("GEOIP_INC_FILE", $_SERVER['DOCUMENT_ROOT'] . "/geoip/geoip.inc");

 

include(GEOIP_INC_FILE);

 

$_geoip = geoip_open(GEOIP_DAT_FILE ,GEOIP_STANDARD);

$_country_code = geoip_country_code_by_addr($_geoip, $_SERVER['REMOTE_ADDR']);

geoip_close($_geoip);

 

switch ($_country_code) {

            case "IN": // India

                              $_SERVER["MAGE_RUN_CODE"] = "india";

                              break; 

            default:

                              $_SERVER["MAGE_RUN_CODE"] = "base";

                                             }