Yii2.0隨筆 路由
阿新 • • 發佈:2018-08-10
directory 默認路由 www ces 你會 添加 php main lena
1、去掉index.php,按照pathinfo模式訪問
例:http://***.com/控制器/方法
(1)把web服務器的網站目錄指向所在模塊的web目錄
(2)在main.php的
‘components‘ => [
‘urlManager‘ => [
‘enablePrettyUrl‘ => true,
],
]
(3)如果沒有去掉index.php,則web目錄添加.htaccess文件
Options +FollowSymLinks
IndexIgnore */*
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
2、缺省路由(默認路由)
(1)如果傳入請求並沒有提供一個具體的路由,(一般這種情況多為於對首頁的請求)此時就會啟用由yii\web\Application::$defaultRoute 屬性所指定的缺省路由。
在return數組中添加
‘defaultRoute‘ => ‘main/index‘,
3、catchAll
路由(全攔截路由)
有時候,你會想要將你的 Web應用臨時調整到維護模式,所有的請求下都會顯示相同的信息頁。
在return數組中添加
‘catchAll‘ => [‘site/offline‘],
Yii2.0隨筆 路由