关于yii2路由优化失效问题(集成环境或者iis配置)

来源:互联网 发布:天刀抄袭剑三 知乎 编辑:程序博客网 时间:2024/06/01 12:37

1:对于集成环境,在配置当中对url进行优化后,需要在网站入口的根目录写入.htaccess文件(以下yii2为案例)


需要在配置文件web.php文件的components写入


'urlManager'=>array(    'enablePrettyUrl' => true, //url进行美化    'showScriptName' => false,//隐藏index.php    'suffix' => '',//后缀    'enableStrictParsing'=>true,//不要求网址严格匹配,则不需要输入rules    'rules' => [    ]//网址匹配规则),


需要写入yii2的项目目录web文件夹下,.htaccess文件内容为

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


2若是使用iis可以使用两种方法


1)使用iis当中的iis目录下的url重写,如图(这里所针对的是iis7以上)



2)就是在同.htaccess同样的文件夹下添加web.config文件,文件内容为

<?xml version="1.0" encoding="UTF-8"?><configuration>    <system.webServer>        <httpErrors errorMode="Detailed" />        <rewrite>            <rules>                <rule name="OrgPage" stopProcessing="true">                    <match url="^(.*)$" />                    <conditions logicalGrouping="MatchAll">                        <add input="{HTTP_HOST}" pattern="^(.*)$" />                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                    </conditions>                    <action type="Rewrite" url="index.php/{R:1}" />                </rule>            </rules>        </rewrite>    </system.webServer></configuration>

原创粉丝点击