1

I currently have 3 domains set up the in the magento admin, only one of these is in use at the moment. I have to set up the other stores for the two other domains, but I don't know how to access these pages without redirecting the domains. How can I set up these sites?

1

In your Apache Virtualhost file you can set up conditions for store codes.

SetEnv Mage_RUN_TYPE website
SetEnv MAGE_RUN_CODE default
SetEnvIfNoCase Host ^(|www).domain1.com$ MAGE_RUN_CODE=websitecode1
SetEnvIfNoCase Host ^(|www).domain2.com$ MAGE_RUN_CODE=websitecode2

Now your index.php file will pick up these variables and show the appropriate website for you. This allows you to ensure maximum upgradability without editing the core code, (index.php).

0

Do you have root access to the server? there are a few way of doing this Making symlinks, but this requires SSH access.

ln -s /path/to/domainname.com/public_html/app ./app
ln -s /path/to/domainname.com/public_html/includes ./includes
ln -s /path/to/domainname.com/public_html/js ./js
ln -s /path/to/domainname.com/public_html/media ./media
ln -s /path/to/domainname.com/public_html/skin ./skin
ln -s /path/to/domainname.com/public_html/var ./var
cp /path/to/domainname.com/public_html/index.php ./index.php
cp /path/to/domainname.com/public_html/.htaccess ./.htaccess

Another way is to add the sites as alias to the same domain as your magento install. and in the root index.php file modify the storeviews that are loaded like this:

Change this line:

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

to this line

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] :
(isset($_SERVER['REDIRECT_MAGE_RUN_CODE']) ? $_SERVER['REDIRECT_MAGE_RUN_CODE'] : '');

then in your .htaccess file do something like this

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(.*)domain1.com
RewriteRule ^ - [E=MAGE_RUN_CODE:]

RewriteCond %{HTTP_HOST} ^(.*)domain2.com
RewriteRule ^ - [E=MAGE_RUN_CODE:]

RewriteCond %{HTTP_HOST} ^(.*)domain2.com
RewriteRule ^ - [E=MAGE_RUN_CODE:]

  • Thanks for the fast reply. I want the other two domains to keep pointing to the live sites for the regular visitors, the new stores would be accessible only for me and the employees at the company (to load the products). Would these changes affect the whole domain? The problem is that all three websites are hosted at the same hosting company on the same server (so the IP address is the same) but with different accounts for each one. – Andras Mar 19 '15 at 16:12
  • You could do some kind of IP check. but i think the way you want it redirections is one of the few options for you. what i do if i have websites i want to test as of its live. and customers need to keep the old version is making it all on a different server on a different ip. and then change your host file. so your computer, and if you want change it on your employees computers as as well. Does that make sence? – Kay Int Veen Mar 19 '15 at 16:35
  • It makes sense, but it's not what I want. Let me refrase my question: I have domain1.com, domain2.com and domain3.com. domain1.com is running magento, domain2.com and domain3.com are running some crappy ecommerce platform that I have never heard of. Because all these three domains sell the same products, my client want's to have a single admin section for all three of them. The solution that you gave me, if I understand it correctly, works only if all these three domains are hosted in the same hosting account, which is not our case. – Andras Mar 19 '15 at 16:50
  • Then im very sorry but you have no other choice i believe. Its eiter a domain alias, or a symlink solution. symlink can be done as long as they are on the same server (same account not needed) but then you cannot seperate it from you/and your employees and the normal customers that need to see the old site. there is just no solution then :( – Kay Int Veen Mar 19 '15 at 16:53
0

Use something like this in your index.php to check the $_SERVER['HTTP_HOST'] and load the right store from that:

/* Store or website code */
//$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
//$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

switch($_SERVER['HTTP_HOST']) {

        case "domain1.com":
        case "www.domain1.com":
                $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain1';
                $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
                break;


        case "domain2.com":
        case "www.domain2.com":
                $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain2';
                $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
                break;


        case "domain3.com":
        case "www.domain3.com":
                $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain3';
                $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
                break;

        default:
                $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain1';
                $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

                break;
}

Mage::run($mageRunCode, $mageRunType);

To Filter by IPs you could:

// grab the ip
$ip = $_SERVER['REMOTE_ADDR']; 
// your allowed ips
$allowed = array('127.0.0.1','Another IP');

and then just check in the above code:

if(in_array($ip, $allowed)){
            case "domain2.com":
            case "www.domain2.com":
                    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain2';
                    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
                    break;
} else {
// domain1
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'domain1';
                    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
                    break;

}
  • Thanks for the fast reply. I want the other two domains to keep pointing to the live sites for the regular visitors, the new stores would be accessible only for me and the employees at the company (to load the products). Would these changes affect the whole domain? The problem is that all three websites are hosted at the same hosting company on the same server (so the IP address is the same) but with different accounts for each one. – Andras Mar 19 '15 at 16:13
  • I suppose you can filter by IPs to direct the correct users to the actual site for that domain, and others to store1. I'll edit my answer. – tecjam Mar 19 '15 at 16:16
0

If anyone else looking to resolve this situation, the answer is that it can't be done. I set up the new stores under some temporary subdomain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.