首页  >  文章  >  php框架  >  yii框架怎么设置伪静态

yii框架怎么设置伪静态

王林
王林原创
2020-02-17 17:44:493892浏览

yii框架怎么设置伪静态

Apache服务器的配置

修改httpd.conf配置文件

1、将LoadModule rewrite_module modules/mod_rewrite.so前面的注释#号去掉。

2、添加如下内容:

<Directory "path/to/basic/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

    # ...other settings...
</Directory>

注意其中的path/to/basic/web修改成你的根目录,最后不要忘记重启apache服务器。

(推荐教程:yii框架

Nginx服务器的配置

修改nginx.conf配置文件,在域名对应的server{}内添加如下内容:

location / {
    # Redirect everything that isn&#39;t a real file to index.php
    try_files $uri $uri/ /index.php$is_args$args;
}

最后不要忘记重载配置文件。

yii2代码的配置

修改config/web.php,在components数组中添加如下内容(去掉前后的注释)

&#39;components&#39; => [
    ...
    &#39;urlManager&#39; => [
        &#39;enablePrettyUrl&#39; => true,
        &#39;showScriptName&#39; => false,
        &#39;rules&#39; => [
        ],
    ],
    ...
],

这时再刷新网页,就能看到连接的形式发生了改变。此时默认会将/index.php?r=controller/action这样的形式修改为/controller/action(如果含有参数,则将/index.php?r=controller/action&...改为/controller/action?...)。

更多编程相关内容,请访问php中文网编程教程栏目!

以上是yii框架怎么设置伪静态的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn