So I'm attempting to setup a second website under Magento, and I'd like it to be on a subdomain, for example, second.mywebsite.com. My main store is mywebsite.com. I've essentially got everything setup on Magento itself, and have the subdomain created.

First, using cPanel, creating a new subdomain automatically points it to /public_html/second and wasn't sure if that's correct since I know it needs to point my root directory.

Second, I'm unsure of the correct configuration for .htaccess to get correct redirecting. I already have one redirect setup for a test environment, located at dev.mywebsite.com. What I have for rewriting currently:

RewriteCond %{HTTP_HOST} !^dev\.mywebsite\.com/$

RewriteRule .* index.php [L]

I know this isn't entirely correct, because right now everything else doesn't redirect correctly back to index.php. For instance, abcd.mywebsite.com gives a "SORRY!" cPanel page.

What I think I need to add:

RewriteCond %{HTTP_HOST} www\.mywebsite\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:site_code1]
RewriteCond %{HTTP_HOST} www\.mywebsite\.com [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]

RewriteCond %{HTTP_HOST} !^second\.mywebsite\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:site_code2]
RewriteCond %{HTTP_HOST} !^second\.mywebsite\.com [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]

Am I headed in the right direction? I basically need to get the two above to redirect properly to the correct website stores, the dev subdomain to redirect correctly and then anything else to the main website.

I have tried above and have no luck on correct redirect.

I've set up the subdomain as shown below, with its document root pointing to the same root of the main site:

enter image description here

Update: I've managed to correctly setup the subdomain as an alias of the the main site. All I'm having trouble with now is getting the site to actually show the correct website/store when using the subdomain. So essentially, the correct syntax for the .htaccess file. Also whether I'm using the Website's code or the Store View's code in that block of code.

1 Answer 1


So after no replies... I decided to cheat and not even use .htaccess. I found a guide that had a special note about Magento versions pre-1.4.

Found from: https://www.properhost.com/support/kb/30/How-To-Setup-Magento-With-Multiple-Stores-And-Domains

I added the following block of code to my index.php:

switch($_SERVER['HTTP_HOST']) {
case 'domain1.com':
case 'www.domain1.com':
    $mageRunCode = 'domain1_com';
    $mageRunType = 'website';
case 'domain2.com':
case 'www.domain2.com':
    $mageRunCode = 'domain2_com';
    $mageRunType = 'website';

above the line:

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

Worked just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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