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

时间:2015-01-22 06:45:54

标签: apache .htaccess rewrite server

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

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

请注意,我希望我的博客网址的格式为abc.com/blog,而不是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=$1 [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/$1 [NC,L]


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

    RewriteRule .* index.php [L]




</IfModule>

2 个答案:

答案 0 :(得分:2)

将以下内容添加到根目录.htaccess:

RewriteEngine on

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

请重新安排.htaccess的结尾部分

#Redirect Blogs

RewriteCond %{HTTP_HOST} ^(?:www\.)?(abc|pqr)\.com$ [NC]
RewriteRule ^blog(?:/(.*))?$ /blogs/%1/$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组合在一起形成了重定向规则。您正在将博客相关规则放在他们之间,破坏了这一功能。

答案 1 :(得分:1)

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

Alias /blog /var/www/blogs/abc

进入abc.com的vhost和pqr.com的vhost的模拟。

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