【问题标题】:Multiple Magento 1.9 Websites/Stores on same domain同一域上的多个 Magento 1.9 网站/商店
【发布时间】:2015-07-04 02:59:14
【问题描述】:

我需要创建单独的零售和批发商店,并计划使用 URL 结构 mysite.com/store 和 mysite.com/wholesale 在同一个域上执行此操作。

我在 Magento 后端创建了单独的网站并输入了相关的不安全/安全的基本 URL。 mysite.com/store 运行良好并显示所有产品等...但是,如果我访问 mysite.com/wholesale,我只会获得标准服务器 404(而不是 Magento 404)。

如何正确设置?我是否需要根目录中的“批发”文件夹或更改 Magento 根目录中的 .htaccess 或类似内容?

关于 SO 或 magento.stackexchange 的每个教程或问题似乎都基于不同域/子域上的单独存储。

【问题讨论】:

    标签: php .htaccess magento e-commerce


    【解决方案1】:

    你使用的是什么网络服务器,你可以通过简单的 nginx 配置来解决这个问题。

    【讨论】:

    • 我使用的是 Apache 网络服务器。
    【解决方案2】:

    问题是当您访问 mysite.com/wholesale 时,Apache Web 服务器认为它是一个目录。这就是为什么你会得到一个 404 而不是 Magento 生成的。您在 Magento 网站的根目录中有标准的 Magento .htaccess 吗?

    【讨论】:

    • 我正在使用 Magento 附带的标准 .htaccess。我需要添加重写规则吗?
    【解决方案3】:

    为了对同一域名下的不同商店使用不同的文件夹,您可以使用相对较新的“将商店代码添加到网址”选项。

    您可以在System > Configuration > Web > Url Options 下找到此选项。 core_config 路径是 web/url/use_store。

    要使用此选项,您应该

    1. 对商店使用相同的基本 URL(无需将/wholesale 文件夹添加到基本 URL)
    2. 将商店代码设置为您希望作为基本网址的子文件夹的名称(例如“wholesale”)

    这与您使用的网络服务器无关。因此无需更改任何 .htaccess 文件。


    如果您想将网站文件夹命名为与您的商店代码不同的名称,您必须创建该文件夹并添加自定义 index.php 以设置正确的商店代码:

    <?php
    
    /**
     * Error reporting
     */
    if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
        error_reporting(E_ALL | E_STRICT);
        ini_set("display_errors", 1);
        ini_set("log_errors", 1);
    } else {
        error_reporting(E_ERROR);
        ini_set("display_errors", 0);
        ini_set("log_errors", 1);
    }
    
    /**
     * Compilation includes configuration file
     */
    define('MAGENTO_ROOT', dirname(getcwd()));
    
    $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
    if (file_exists($compilerConfig)) {
        include $compilerConfig;
    }
    
    $mageFilename = MAGENTO_ROOT . '/app/Mage.php';
    $maintenanceFile = 'maintenance.flag';
    php_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;
    
    /**
     * Enable developer mode
     */
    if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
        Mage::setIsDeveloperMode(true);
    }
    umask(0);
    
    Mage::run('wholesale', 'store');
    

    除了两个位置之外,默认 index.php 几乎没有变化

    • 你必须告诉 Magento 它的真正根在哪里:define('MAGENTO_ROOT', dirname(getcwd()));
    • 并且必须指定商店代码:Mage::run('wholesale', 'store');

    所有其他行都是标准 Magento。

    理论上你也应该能够通过重写规则来完成同样的事情,但我从来没有让它正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      相关资源
      最近更新 更多