Yii框架的路由配置方法分析

2022-04-14 0 1,025

本文实例讲述了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',
      ],
    ],

更多关于Yii相关内容感兴趣的读者可查看本站专题

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 PHP编程 Yii框架的路由配置方法分析 https://www.niceym.com/12486.html