Yii框架的路由配置方法分析
发布:smiling 来源: PHP粉丝网 添加日期:2021-12-16 10:27:39 浏览: 评论:0
本文实例讲述了Yii框架的路由配置方法,分享给大家供大家参考,具体如下:
取消index.php
这两种方法都是在自动添加index.php
方法一:使用.htaccess
添加.htaccess文件 与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
方法二:vhost
- <VirtualHost *:80>
- ServerName public.oa.com
- DocumentRoot "D:\phpStudy\PHPTutorial\WWW\OA\frontend\web"
- <Directory "D:\phpStudy\PHPTutorial\WWW\OA\frontend\web">
- # use mod_rewrite for pretty URL support
- 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
- # use index.php as index file
- DirectoryIndex index.php
- # ...other settings...
- # Apache 2.4
- Require all granted
- ## Apache 2.2
- # Order allow,deny
- # Allow from all
- </Directory>
- </VirtualHost>
Yii配置
- 'urlManager' => [
- //美化路由
- 'enablePrettyUrl' => true,
- //不启用严格解析
- 'enableStrictParsing' => false,
- //index.php是否显示
- 'showScriptName' => false,
- //伪静态化 seo
- 'suffix' => '.html',
- //美化规则
- 'rules' => [
- //第一条:文章详细页
- '<controller:\w+>/<id:\d+>'=>'<controller>/detail',
- //第二条:文章列表页
- 'post'=>'post/index',
- ],
- ],
Tags: Yii框架路由配置
- 上一篇:Yii框架连表查询操作示例
- 下一篇:Yii框架函数简单用法分析
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)