Yii2.0随笔 路由

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)如果传入请求并没有提供一个具体的路由,(一般这种情况多为于对首页的请求)此时就会启用由yiiwebApplication::$defaultRoute 属性所指定的缺省路由。

在return数组中添加

'defaultRoute' => 'main/index',

3、catchAll 路由(全拦截路由)

有时候,你会想要将你的 Web应用临时调整到维护模式,所有的请求下都会显示相同的信息页。

在return数组中添加

'catchAll' => ['site/offline'],

原文地址:https://www.cnblogs.com/zsczsc/p/9452847.html