【问题标题】:Configuring Blogs on a multi site Magento setup在多站点 Magento 设置上配置博客
【发布时间】:2015-03-20 21:21:19
【问题描述】:

我有两个网站说 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 而不是 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>

【问题讨论】:

    标签: apache .htaccess rewrite server


    【解决方案1】:

    将以下内容添加到您的根 .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 一起形成重定向规则。您将博客相关规则放在他们之间,破坏了该功能。

    【讨论】:

    • 当我在上面写这段代码时################################## ######### ## 将其他所有内容重写为 index.php RewriteRule .* index.php [L] - 请求 example.com/blog/redirectswww/example.com 其中 example = abc。
    • 请在问题中发布您当前的 htaccess,以便我更好地理解您的规则。
    • 从我的 .htaccess 中添加了重定向部分
    【解决方案2】:

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

    Alias /blog /var/www/blogs/abc
    

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

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

    【讨论】:

    • 我已经在 /var/www/vhosts/abc/conf/ 中创建了 vhost.conf,并且只输入了上述行。需要重启服务器吗?
    猜你喜欢
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多