来自: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
最终前端网址:http:// example.com/
- >行。
最终后端网址:http:// example.com/backend
- >错误404。
最后一个后端网址:http:// example.com/backend2
- >行。
答案 0 :(得分:0)
您需要根据此修改String eqPattern = "(.*)=\\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/backend2
文件夹,并修复后端2的所有名称空间和路径。