我創建了管理模塊,我的網站根目錄指向web
目錄。Yii2管理模塊通過URL訪問domain.com/admin/login
因此,我需要做些什麼來實現domain.com/admin
作爲我的模塊的基本URL。管理模塊內部的任何操作應該看起來像domain.com/admin/controller/action
這是我的目錄結構。
在此先感謝。
我創建了管理模塊,我的網站根目錄指向web
目錄。Yii2管理模塊通過URL訪問domain.com/admin/login
因此,我需要做些什麼來實現domain.com/admin
作爲我的模塊的基本URL。管理模塊內部的任何操作應該看起來像domain.com/admin/controller/action
這是我的目錄結構。
在此先感謝。
配置你的urlManager:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
在你的文件的根放的.htaccess
Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(.+)?$ backend/web/$1 [L,PT]
把第二的.htaccess中/後端文件夾。
Options -Multiviews
Options +FollowSymLinks
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . web
#RewriteRule . index.php
,並把像
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
在後臺/網頁/文件夾中其他的.htaccess
開箱即用yii2處理像模塊/控制器/動作這樣的路由,當您像這樣請求它們時:example.com/index.php?r=module/controller/action。爲了使它們看起來像你想你需要:
配置您的urlManager
:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
啓用配置的模塊:
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
],
],
而且在的.htaccess
配置重寫規則<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>