Yii 1.0 伪静态即Yii配置Url重写(转)

第一步:配置 URL Management(网址管理)

只需要在config文件夹下面的main.php文件中进行配置就好了

到配置文件中开启:

LoadModule rewrite_module modules/mod_rewrite.so

'components' => array(
    'urlManager' => [
      'showScriptName' => false,//这里是隐藏index.php那个路径的
      'urlFormat' => 'path',
      'rules' => [
        '<controller:w+>/<id:d+>' => '<controller>/view',
        '<controller:w+>/<action:w+>/<id:d+>' => '<controller>/<action>',
        '<controller:w+>/<action:w+>' => '<controller>/<action>'
      ]
    ],
    'user' => array(
      
      // enable cookie-based authentication
      'allowAutoLogin' => true
    ),<span style="font-family: Arial, Helvetica, sans-serif;">)</span>

第二步:进行apache配置

yii中有个文件:.htaccess 用来专门配置apache服务器的,这个文件下面配置输入下面的代码

<IfModule mod_rewrite.c>
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
</IfModule>

这个文件配置好了之后,一定要把apache中的rewrite模块开启:

然后就OK了。

整个URL的配置就已经完成了。

原文地址:https://www.cnblogs.com/lccjob/p/4879028.html