0

I'm trying to run multi-store environment (2 websites) on single Magento instance according to this post :https://www.nublue.co.uk/blog/creating-a-magento-multi-store-using-symlinks/ but I can't figure it out

The main website works fine but the second one redirect to the primary website.

Here are my index.php and .htaccess :


Index.php

define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

if ($_SERVER['HTTP_HOST'] == "domaine2.com" || $_SERVER['HTTP_HOST'] == "www.domaine2.com"){$_SERVER["MAGE_RUN_CODE"] = "domaine2"; $_SERVER["MAGE_RUN_TYPE"] = "store"; }


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

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

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

Htaccess

    SetEnvIf Host www\.domain1\.com MAGE_RUN_CODE=domain1
    SetEnvIf Host www\.domain1\.com MAGE_RUN_TYPE=store

    SetEnvIf Host www\.domain2\.com MAGE_RUN_CODE=domain2
    SetEnvIf Host www\.domain2\.com MAGE_RUN_TYPE=store




#################################################################### 
################## Creare's Magento .htaccess File #################
#################################################################### 

##### Block unwanted Bots that clog the server #####



        RewriteCond %{HTTP_USER_AGENT} MJ12bot
        RewriteRule .* - [F]
        RewriteCond %{HTTP_USER_AGENT} 80legs [NC]
        RewriteRule ^ - [F]

##### Add support for SVG Graphics and CSS3 Pie #####



        AddType image/svg+xml svg svgz
        AddEncoding gzip svgz
        AddType text/x-component .htc
        DirectoryIndex index.php 

##### Domain-specific PHP Settings #####

    <IfModule mod_php5.c> 
        php_value memory_limit 1024M 
        php_value max_execution_time 18000 
        php_flag magic_quotes_gpc off 
        php_flag session.auto_start off 
        php_flag suhosin.session.cryptua off 
        php_flag zend.ze1_compatibility_mode Off 
    </IfModule>

##### Necessary redirects and rewrites for search engines #####

<IfModule mod_rewrite.c>

    RewriteCond %{HTTP_HOST} !^www.domaine1.com$ [NC]
    RewriteRule ^(.*)$ http://www.domaine1.com/$1 [R=301,L]



    ##### Redirect away from /index.php and /home   
    ##### Warning: This index.php rewrite will prevent Magento 
    ##### Connect from working. Simply comment out the  
    ##### following two lines of code when using Connect.
    ##### Please note - http://www. if not using www simply use http://


    ##### Please note - http://www. if not using www simply use http://
    redirect 301 /home http://www.domaine1.com

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule .* index.php [L]
</IfModule>


##### mod_deflate compresses your output to lower the file size being sent to the client #####

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
    php_flag zlib.output_compression on
</IfModule>

<Files *.php>
    SetOutputFilter DEFLATE 
</Files>

<IfModule mod_ssl.c>
    SSLOptions StdEnvVars 
</IfModule>


##### disable POST processing to not break multiple image upload #####

<IfModule mod_security.c> 
    SecFilterEngine Off 
    SecFilterScanPOST Off
</IfModule> 


##### Enable apache served files compression #####

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
                    AddOutputFilterByType DEFLATE image/x-icon
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
</IfModule>


##### Mod gzip and caching for improved site speed #####

<ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule>


##### Default expires headers for all file types  #####
##### Not recommended for development environment #####

<ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType text/html "access plus 1 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 216000 seconds"
    ExpiresByType application/x-javascript "access plus 216000 seconds"
                    ExpiresByType text/x-javascript "access plus 1 month"  
                    ExpiresByType application/javascript "access plus 1 month"
                    ExpiresByType image/x-icon "access plus 1 year”

</ifModule> 


##### Mime Type Caching #####

<IfModule mod_mime.c>

    ##### AUDIO #####
    AddType audio/mp4 m4a f4a f4b
    AddType audio/ogg oga ogg

    ##### JAVASCRIPT #####
    # Normalize to standard type (it's sniffed in IE anyways):
    # http://tools.ietf.org/html/rfc4329#section-7.2
    AddType application/javascript                      js jsonp
    AddType application/json                            json

    ##### VIDEO #####
    AddType video/mp4                                   mp4 m4v f4v f4p
    AddType video/ogg                                   ogv
    AddType video/webm                                  webm
    AddType video/x-flv                                 flv

    ##### WEB FONTS #####
    AddType application/font-woff                       woff
    AddType application/vnd.ms-fontobject               eot

    ##### Browsers usually ignore the font MIME types   #####
    ##### and sniff the content, however, Chrome shows  #####
    ##### a warning if other MIME types are used for    #####
    ##### the following fonts.                          #####
    AddType application/x-font-ttf                      ttc ttf
    AddType font/opentype                               otf


    ##### OTHER #####
    AddType application/octet-stream                    safariextz
    AddType application/x-chrome-extension              crx
    AddType application/x-opera-extension               oex
    AddType application/x-shockwave-flash               swf
    AddType application/x-web-app-manifest+json         webapp
    AddType application/x-xpinstall                     xpi
    AddType application/xml                             atom rdf rss xml
    AddType image/webp                                  webp
    AddType image/x-icon                                ico
    AddType text/cache-manifest                         appcache manifest
    AddType text/vtt                                    vtt
    AddType text/x-component                            htc
    AddType text/x-vcard                                vcf

</IfModule>

<IfModule mod_mime.c>
    AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
</IfModule>


##### Disable ETags http://developer.yahoo.com/performance/rules.html#etags #####

    FileETag None


##### Prevent character encoding issues from server overrides #####

    AddDefaultCharset Off
    #AddDefaultCharset UTF-8


##### Force IE8 compatibility when using IE8+         #####
##### May cause issues within Windows Mobile Browsers ##### 

    BrowserMatch MSIE best-standards-support
    Header set X-UA-Compatible IE=8 env=best-standards-support


##### By default allow all access #####

    Order allow,deny
    Allow from all
4
  • please refer it is useful code.tutsplus.com/tutorials/… Oct 2, 2015 at 19:57
  • Make sure, your env settings are read in index.php Oct 2, 2015 at 20:11
  • dont move files anywhere, no symlinks etc, just add store code to .htaccess, then add second store base url to magento store view, and createnew design package name if you need.
    – user2857
    Oct 3, 2015 at 15:03
  • Downvoting every answer is not exactly an encouragement for more people to help you Oct 4, 2015 at 15:25

3 Answers 3

1

Add the domain2 in:

- System
- Settings
**** - Switch the storeview to store (view) 2****
- General
- Web

Add the domain2 in URL Base

1

Please add below code in index.php file. No need to modify .htaccess file.

switch($_SERVER['HTTP_HOST']) { case 'example1.com': /* Store or website code / $mageRunCode = 'base'; / Run store or run website / $mageRunType = 'website1'; break; case 'example2.com': / Store or website code / $mageRunCode = 'store2'; / Run store or run website */ $mageRunType = 'website1'; break;

default: /* 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'; }

1

I suppose you have followed the steps to create website or store from Magento backend. This is the code for .htaccess

RewriteCond %{HTTP_HOST} www\.domain1\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:websitecode]
RewriteCond %{HTTP_HOST} www\.domain1\.biz/onedemo/ [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]

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

Here is the code for index.php

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

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

Make sure you have changed the base url for new store. System > configuration > Current configuration scope > Select website > web > change the base url and change for js, media and skin if needed.

Give path for new website and don't forget symlinks by following this commands using SSH.

ln -s ../public_html/app ./app
ln -s ../public_html/errors ./errors
ln -s ../public_html/includes ./includes
ln -s ../public_html/js ./js
ln -s ../public_html/lib ./lib
ln -s ../public_html/media ./media
ln -s ../public_html/skin ./skin
ln -s ../public_html/var ./var
1
  • In localhost, how to create symbolic links.
    – zus
    Feb 22, 2018 at 6:02

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.