经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » PHP » 查看文章
Yii框架的路由配置方法分析
来源:jb51  时间:2019/9/10 10:26:26  对本文有异议

本文实例讲述了Yii框架的路由配置方法。分享给大家供大家参考,具体如下:

取消index.php

这两种方法都是在自动添加index.php

方法一:使用.htaccess

添加.htaccess文件  与index.php同级

  1. RewriteEngine on
  2. # if a directory or a file exists, use the request directly
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. # otherwise forward the request to index.php
  6. RewriteRule . index.php
  7.  

方法二:vhost

  1. <VirtualHost *:80>
  2. ServerName public.oa.com
  3. DocumentRoot "D:\phpStudy\PHPTutorial\WWW\OA\frontend\web"
  4. <Directory "D:\phpStudy\PHPTutorial\WWW\OA\frontend\web">
  5. # use mod_rewrite for pretty URL support
  6. RewriteEngine on
  7. # If a directory or a file exists, use the request directly
  8. RewriteCond %{REQUEST_FILENAME} !-f
  9. RewriteCond %{REQUEST_FILENAME} !-d
  10. # Otherwise forward the request to index.php
  11. RewriteRule . index.php
  12. # use index.php as index file
  13. DirectoryIndex index.php
  14. # ...other settings...
  15. # Apache 2.4
  16. Require all granted
  17. ## Apache 2.2
  18. # Order allow,deny
  19. # Allow from all
  20. </Directory>
  21. </VirtualHost>
  22.  

Yii配置

  1. 'urlManager' => [
  2. //美化路由
  3. 'enablePrettyUrl' => true,
  4. //不启用严格解析
  5. 'enableStrictParsing' => false,
  6. //index.php是否显示
  7. 'showScriptName' => false,
  8. //伪静态化 seo
  9. 'suffix' => '.html',
  10. //美化规则
  11. 'rules' => [
  12. //第一条:文章详细页
  13. '<controller:\w+>/<id:\d+>'=>'<controller>/detail',
  14. //第二条:文章列表页
  15. 'post'=>'post/index',
  16. ],
  17. ],
  18.  

更多关于Yii相关内容感兴趣的读者可查看jb51专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号