在多站点 Magento 设置上配置博客

Configuring Blogs on a multi site Magento setup

我有两个网站 abc.com 和 pqr.com 运行 来自同一个 Magento 安装。现在我想通过 wordpress 为每个域创建博客,为此我在根 Magento 目录中创建了一个文件夹 "blogs" 并在名为 blogs/abc 和 blogs/pqr 的文件夹中安装了两个 wordpress 实例.

如何在根目录中配置我的 .htaccess 或 index.php,以便对 www.abc.com/blog 和 www.pqr.com/blog 的请求是分别路由到文件夹 blogs/abc 和 blogs/pqr。

请注意,我希望我的博客 URL 的格式为 abc。com/blog 而不是博客。abc.com

############################################
## you can put here your magento root folder
## path relative to web root

    RewriteBase /

############################################
## uncomment next line to enable light API calls processing

#    RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type= [QSA,L]

############################################
## rewrite API2 calls to api.php (by now it is REST only)

    RewriteRule ^api/rest api.php?type=rest [QSA,L]

############################################
## workaround for HTTP authorization
## in CGI environment

    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

    RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
    RewriteRule .* - [L,R=405]

############################################
## redirect for mobile user agents

    #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
    #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
    #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

############################################
## always send 404 on missing files in these folders

    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################
## never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l


#Redirect Blogs

#RewriteCond %{HTTP_HOST} ^(?:www\.)?(abc|pqr)\.com$ [NC]
#RewriteRule ^blog(?:/(.*))?$ /blogs/%1/ [NC,L]


############################################
## rewrite everything else to index.php

    RewriteRule .* index.php [L]




</IfModule>

如果您有权访问 vhost 配置(通常 /etc/apaches/sites-enabled/abc),只需输入

Alias /blog /var/www/blogs/abc

进入 abc.com 的虚拟主机,模拟 pqr.com 的虚拟主机。

您还需要启用 mod_alias。这不可能在 .htaccess 文件中完成,另请参阅 this document

将以下内容添加到您的根 .htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(?:www\.)?(abc|pqr)\.com$ [NC]
RewriteRule ^blog(?:/(.*))?$ /blogs/%1/ [NC,L]

请将 .htaccess 的结尾部分重新排列为

#Redirect Blogs

RewriteCond %{HTTP_HOST} ^(?:www\.)?(abc|pqr)\.com$ [NC]
RewriteRule ^blog(?:/(.*))?$ /blogs/%1/ [NC,L]

############################################
## rewrite everything else to index.php
## but never rewrite for existing files, directories and links

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

请注意 RewriteCond 和紧随其后的 RewriteRule 一起构成重定向规则。您将博客相关规则放在它们之间破坏了该功能。