0

I'm getting 404 / apache error issues while trying to configure multiple stores having the same domain name and specific URI "directory"

What I have done

vhost config

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/var/www/html/dev-site/code"
    ServerName my.domain.local

    Alias /alias1 /var/www/html/dev-site/code
    Alias /alias2 /var/www/html/dev-site/code
    Alias /alias3 /var/www/html/dev-site/code

   <Directory /var/www/html/dev-site/code>
            Order allow,deny
            Allow from all
            AllowOverride All
            RewriteEngine On
            Options +FollowSymlinks
    </Directory>

    SetEnvIf Request_URI ^/alias1(.*) MAGE_RUN_CODE=pf_view
    SetEnvIf Request_URI ^/alias1(.*) MAGE_RUN_TYPE=store

    SetEnvIf Request_URI ^/alias2(.*) MAGE_RUN_CODE=es_view
    SetEnvIf Request_URI ^/alias2(.*) MAGE_RUN_TYPE=store

    SetEnvIf Request_URI ^/alias3(.*) MAGE_RUN_CODE=ta_view
    SetEnvIf Request_URI ^/alias3(.*) MAGE_RUN_TYPE=store
</VirtualHost>

Magento config

  • In core_config_data, default base_url is set to "http://domain.local/" (so we can access admin at http://domain.local/admin)
  • Each store base_url is set as "http://my.domain.local/aliasX/" (replace X by 1, 2 or 3)
  • Every single js/media/skin base url is explicitely specified and common for all aliases (e.g. http://my.domain.local/js/)
  • index.php is tweaked so it can handle "REDIRECT_" server vars :

    /* Store or website code */
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
    if ('' == $mageRunCode) {
        $mageRunCode = isset($_SERVER['REDIRECT_MAGE_RUN_CODE']) ? $_SERVER['REDIRECT_MAGE_RUN_CODE'] : $mageRunCode;
    }
    
    /* Run store or run website */
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
    if ('store' == $mageRunType) {
        $mageRunType = isset($_SERVER['REDIRECT_MAGE_RUN_TYPE']) ? $_SERVER['REDIRECT_MAGE_RUN_TYPE'] : $mageRunType;
    }
    

What I get

This config is not enough (or is wrong) to make it work :

  • In index.php, when I dump $mageRunCode just before the Mage::run() line, I get the correct value
  • All homepages work (http://my.domain.local/aliasX/)
  • When I set RewriteBase to /alias1/, all /alias1 based urls are working but not the others
  • All other aliases' urls are redirected to alias1 homepage (and the dump shows the alias1 run code). This is normal, as I set RewriteBase to /alias1/

What I already tried and isn't described above

  • I tried tu use <Location> in my vhost config to set conditional RewriteBase. But with Locations set, my urls are not correctly redirected to index.php and I get the good ol' white apache 404 page (with apache error logs like this one : File does not exist: /var/www/html/dev-site/code/catalog, referer: http://my.domain.local/alias1/)

What I dont want

vhost aliases pointing to subdirectories + duplicated .htaccess and index.php in these subdirectories

Any help, clue, link - you name it - will be highly appreciated (I'm not a sysadmin and currently wasting my client's money not being able to solve this issue)

0

You can try this:

NameVirtualHost *:80
DocumentRoot "/var/www/html/dev-site/code"
ServerName my.domain.local
RewriteEngine On
SetEnvIf Request_URI ^/alias1.* MAGE_RUN_CODE=pf_view
SetEnvIf Request_URI ^/alias1.* MAGE_RUN_TYPE=store
SetEnvIf Request_URI ^/alias2.* MAGE_RUN_CODE=es_view
SetEnvIf Request_URI ^/alias2.* MAGE_RUN_TYPE=store
SetEnvIf Request_URI ^/alias3.* MAGE_RUN_CODE=ta_view
SetEnvIf Request_URI ^/alias3.* MAGE_RUN_TYPE=store
<Directory /var/www/html/dev-site/code>
Order allow,deny
Allow from all
AllowOverride All
RewriteEngine On
Options +FollowSymlinks
</Directory>
  • Without RewriteBase i'm getting a Magento 404 error (skinned) for any page, home pages included. With a RewriteBase (say, /alias1/), I'm getting a brutal Internal Server Error With following apache error log : Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. – LittleBigDev Oct 15 '15 at 7:11

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.