2015-08-16 139 views
0

我創建了管理模塊,我的網站根目錄指向web目錄。Yii2管理模塊通過URL訪問domain.com/admin/login

因此,我需要做些什麼來實現domain.com/admin作爲我的模塊的基本URL。管理模塊內部的任何操作應該看起來像domain.com/admin/controller/action

這是我的目錄結構。

enter image description here

在此先感謝。

回答

1

配置你的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
0

開箱即用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>