【问题标题】:Configure Yii2 Advanced on single domain with multiple backends在具有多个后端的单个域上配置 Yii2 Advanced
【发布时间】:2017-02-16 00:29:19
【问题描述】:

发件人:http://www.yiiframework.com/wiki/799/yii2-app-advanced-on-single-domain-apache-nginx/#hh2

它可以工作,但我创建了另一个后端。

这是我拥有的.htaccess 配置:

RewriteEngine On    

# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend2)/web/ - [L]
RewriteRule ^(frontend|backend)/web/ - [L]  

# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^backend(/(.*))?$ backend/web/$2 [S=1]
RewriteRule ^backend2(/(.*))?$ backend2/web/$3 [S=2] 

# handle the case of frontend
RewriteRule .* frontend/web/$0    

# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php

最终的前端 URL:http:// example.com/ -> 好的。

最终的后端 URL:http:// example.com/backend -> 错误 404。

最终的另一个后端 URL:http:// example.com/backend2 -> 好的。

【问题讨论】:

  • 为什么是S 标志?在这两种情况下都使用 [L]。
  • 什么是[L]?我不知道。我正在学习Yii2。帮帮我
  • L 表示Last,因此当此规则匹配时,它将停止处理其他规则。这不是 Yii 2 的问题,它是 Apache 重写模块 - 见 httpd.apache.org/docs/2.4/rewrite/flags.html

标签: .htaccess yii2


【解决方案1】:

你需要根据这个编辑你的.htaccess

RewriteEngine On

# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend|backend2)/web/ - [L]

# Handle the case of backend, skip ([S=2]) two following rules, if current matched
RewriteRule ^backend(/(.*))?$ backend/web/$2 [S=2]

# Handle the case of backend2, skip ([S=1]) the following rule, if current matched
RewriteRule ^backend2(/(.*))?$ backend2/web/$2 [S=1]

# handle the case of frontend
RewriteRule .* frontend/web/$0

# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php

你需要编辑backend2/config/main.php:

....
    'components' => [
        ....
        'request'=>[
            'baseUrl'=>'/backend2',
        ],
        'urlManager'=>[
            'scriptUrl'=>'/backend2/index.php',
        ],
        // use the following, if you want to enable speaking URL for the backend
//        'urlManager' => [
//            'enablePrettyUrl' => true,
//            'showScriptName' => false,
//        ],
    ],

此外,您需要创建具有适当内容的environments/dev/backend2environments/prod/backend2 文件夹,并修复所有命名空间和后端2 的路径。

【讨论】:

    猜你喜欢
    • 2017-08-19
    • 2015-03-31
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    相关资源
    最近更新 更多