IIS配置web.config文件隐藏index.php实现伪静态/重定向功能的简单配置

web.config是xml配置文件,用于在IIS服务器下对url请求做重定向操作,简单举几个例子:

规则都是写在rules里的,可多条

具体的规则结构为:

<rule>
<!--正则匹配 例如所有的请求 取得请求参数使用{R:1}即可,{R:N}即为第N个匹配位的值-->
<match url="^.*$" />
    <conditions>
        <!--negate为无效设置,这里主要是把目录请求or文件css js 图片什么的排除-->
        <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}" logRewrittenUrl="true" />
</rule>

这样一条规则就可以使我们隐藏index.php入口文件。

多条列子,第一条规则为将请求定位到en英文目录下,不详细解释了,我相信大家能领悟出其中的逻辑来

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <!--规则开始-->
            <rules>
            <!--规则名name不可重复 stopProcessing跳出解析-->
             <rule name="en" stopProcessing="true">
                <match url="^(en)/(.*$)"/>
                <conditions>
                    <!--negate为无效设置,这里主要是把目录请求or文件css js 图片什么的排除-->
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="{R:1}/index.php/{R:2}" logRewrittenUrl="true" />
            </rule>
            <!--多条规则-->
            <rule name="Wapcms" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions>
                    <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}" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>


转载于:https://my.oschina.net/sallency/blog/390907

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值