以下是本地系统上的虚拟主机:
<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>
管理后端,因此设置为dev.com/webxadmin/login
下面是将名称更改为backend / web / index.php到&#34; webxadmin&#34;的程序。
<?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();
}
}
}
后端/配置/ 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/$1 [L]
RewriteRule ^webxadmin/css/(.*)$ backend/web/css/$1 [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/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [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
这是我的后端/ module / seller / seller.php中的模块 使用yii-2项目我有电子商务网站我试图访问我的卖家模块在子域名如seller.dev.com与所有控制器和行动?
但我需要在子域中访问我的模块我该怎么做?
我在组件中尝试了这个方法 - &gt; urlmanager无效。
'seller.dev.com/'=>'seller/index/login',
先谢谢。
答案 0 :(得分:4)
如果您正在使用自定义请求组件和.htaccess 选项+ FollowSymlinks RewriteEngine On
Post
.htaccess文件的结尾添加以下行。
# deal with admin first
RewriteCond %{REQUEST_URI} ^/(webxadmin)
RewriteRule ^webxadmin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^webxadmin/css/(.*)$ backend/web/css/$1 [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/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [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
答案 1 :(得分:0)
匹配rule based on hostnames的正确语法是:
'http://seller.dev.com'=>'seller/index/login',
如果这不起作用,您应该在自定义重写逻辑或Request类中查找问题。我真的不明白你在那里做什么。
从Yii 2.0.11开始,您还可以使用以下语法来获得与http
和https
一起使用的协议相对URL:
'//seller.dev.com'=>'seller/index/login',