我在Magento的一次安装中有两个存储,并且第二个存储有一个单独的域,该域仅指向主要安装(第二个域中根本没有文件)。但是,当用户通过第二个域访问时,第二个商店未加载,默认商店的类别和产品也已加载。我在Magentos根目录的.htaccess文件中添加了以下几行,但它们似乎不起作用。
############################################
enable rewrites
SetEnvIf Host www\.testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host www\.testsite\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host ^testsite\.com MAGE_RUN_TYPE=website
Options +FollowSymLinks
RewriteEngine on
############################################
shoe_store是第二个商店的“网站名称”的代码,而不是“商店视图名称”的代码,但它们都不起作用。我不确定所有的反斜杠是什么,但是它们在我阅读的所有教程中都有。我还检查了“安全”和“不安全”部分中的基本URL,它是正确的地址,并在末尾带有一个/(http://testsite.com/)。
我有多家商店在处理子域,但事实证明,单独的域更加困难。有人知道我在做什么错吗?
编辑:在下面的index.php代码中添加
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
if (version_compare(phpversion(), '5.2.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
Magento using PHP-CGI as a work-around.</p></div>';
exit;
}
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
/**
* Compilation includes configuration file
*/
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_once $mageFilename;
#Varien_Profiler::enable();
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
umask(0);
/* 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';
if (file_exists($autoload = __DIR__.'/vendor/autoload.php')) {
require_once $autoload;
}
switch($_SERVER['HTTP_HOST']) {
case 'mainsite.com':
case 'www.mainsite.com':
$mageRunCode = 'base'; //not your website code, it should be code for your first store
$mageRunType = 'website'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
break;
case 'testsite.com':
case 'www.testsite.com':
$mageRunCode = 'shoe_store'; //code of second store
$mageRunType = 'website';
break;
}
Mage::run($mageRunCode, $mageRunType);
最佳答案
通过解决您的问题,我认为您的域运行正常。但是,对于您的两个域,正在加载同一存储(默认存储)。这是因为您没有指定要为哪个域加载的存储。对于magento,您的两个域是陌生人,因此它将为每个域加载默认存储。
因此,我们想通知magento,对于每个域,应该加载一个特定的商店。商店正在index.php
本身(在根目录中)加载。
请转到index.php文件,您将看到加载欲望商店和商店视图的最后一行。我们需要对其进行一些更改,以便使magento可以根据需要加载正确的商店。
因此,在此代码段Mage::run($mageRunCode, $mageRunType);
上方添加以下代码
switch($_SERVER['HTTP_HOST']) {
case 'firstdomain.com':
case 'www.firstdomain.com':
$mageRunCode = 'store_code'; //not your website code, it should be code for your first store
$mageRunType = 'store'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
break;
case 'seconddomain.com':
case 'www.seconddomain.com':
$mageRunCode = 'store_code'; //code of second store
$mageRunType = 'store';
break;
}
Mage::run($mageRunCode, $mageRunType);
希望有帮助...
关于magento - Magento多个商店问题-第二个域正在加载默认商店产品,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22645934/