是否可以将子域分配给模块?例如seller.domain.com到卖家模块

Is it possible to assign subdomain to module? For example seller.domain.com to seller module

下面是我在本地系统上的虚拟主机:

<VirtualHost *:80>
ServerAdmin kishan@localhost.com
DocumentRoot /opt/lampp/htdocs/advanced
ServerName dev.com
ServerAlias dev.com
ErrorLog logs/mysite.local-error_log
CustomLog logs/mysite.local-access_log common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin kishan@localhost.com
DocumentRoot /opt/lampp/htdocs/advanced
ServerName seller.dev.com
ServerAlias seller.dev.com
ErrorLog logs/mysite.local-error_log
CustomLog logs/mysite.local-access_log common
</VirtualHost>

为开发人员设置的管理后端。com/webxadmin/login

以下是将名称从 backend/web/index.php 更改为 "webxadmin".

的过程
<?php
namespace common\components;


class Request extends \yii\web\Request {
    public $web;
    public $adminUrl;

    public function getBaseUrl(){
        return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
    }


    /*
        If you don't have this function, the admin site will 404 if you leave off 
        the trailing slash.

        E.g.:

        Wouldn't work:
        site.com/admin

        Would work:
        site.com/admin/

        Using this function, both will work.
    */
    public function resolvePathInfo(){
        if($this->getUrl() === $this->adminUrl){
            return "";
        }else{
            return parent::resolvePathInfo();
        }
    }
}

backend/config/main.php

'components' => [
        'request' => [
            'class' => 'common\components\Request',
            'web'=> '/backend/web',
            'adminUrl' => '/webxadmin'
        ],

这是 root 上的 .htaccess

Options +FollowSymlinks
RewriteEngine On

# deal with admin first

RewriteCond %{REQUEST_URI} ^/(webxadmin)
RewriteRule ^webxadmin/assets/(.*)$ backend/web/assets/ [L]
RewriteRule ^webxadmin/css/(.*)$ backend/web/css/ [L]

RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/(webxadmin)
RewriteRule ^.*$ backend/web/index.php [L]




RewriteCond %{REQUEST_URI} ^/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
RewriteRule ^css/(.*)$ frontend/web/css/ [L]

RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php

这是我的模块 backend/module/seller/seller。php 使用 yii-2 项目,我有电子商务网站,我正在尝试使用所有控制器和操作访问 seller.dev.com 等子域上的我的卖家模块?

但我需要在子域中访问我的模块,我该怎么做?

我在component->urlmanager里面试过这个方法没有用

'seller.dev.com/'=>'seller/index/login',

提前致谢。

匹配 rule based on hostnames 的正确语法是:

'http://seller.dev.com'=>'seller/index/login',

如果这不起作用,您应该在自定义重写逻辑或请求 class 中查找问题。我真的不明白你想在那里做什么。

从 Yii 2.0.11 开始,您还可以使用以下语法来获得与 httphttps 一起工作的相对 URL 协议:

'//seller.dev.com'=>'seller/index/login',

如果您正在使用自定义请求组件和 .htaccess。
选项 +FollowSymlinks 重写引擎开启

# deal with admin first

RewriteCond %{REQUEST_URI} ^/(webxadmin)
RewriteRule ^webxadmin/assets/(.*)$ backend/web/assets/ [L]
RewriteRule ^webxadmin/css/(.*)$ backend/web/css/ [L]

RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/(webxadmin)
RewriteRule ^.*$ backend/web/index.php [L]




RewriteCond %{REQUEST_URI} ^/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/ [L]
RewriteRule ^css/(.*)$ frontend/web/css/ [L]

RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php

.htaccess 文件末尾添加下面一行。

RewriteRule ^.*$ backend/web/index.php