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

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值