IIS7 伪静态 web.config 配置方法【详解】

IIS7 做伪静态比较的简单方便  

1.程序方面

只需要设置web.config 就可以了。

2.服务器需要安装:URL Rewrite

下载地址:http://www.iis.net/download/URLRewrite

Godaddy 的主机已经安装这个插件。

本地在测试的时候 请查看自己是否安装这个插件。

注意要点

1.参数用“()” 括起来 ,使用 {R:1}来获得参数

2.多个参数中间用 & 分割

3.name切记不能写一样 

<?xml version="1.0"?>
 
<configuration>
<system.webServer>
        <rewrite>
            <rules>
                <!--301重定向把不带3W的域名 定向到带3W-->
                <rule name="Redirect" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^haoxinwen.info$" />
                    </conditions>
                    <action type="Redirect" url="http://www.haoxinwen.info/{R:0}" redirectType="Permanent" />
                </rule>
                <!--首页-->
                <rule name="rD">
                    <match url="^$" />
                    <action type="Rewrite" url="Default.aspx" />
                </rule>
                <!--产品列表-->
                <rule name="rP">
                    <match url="^product/$" />
                    <action type="Rewrite" url="ProductList.aspx" />
                </rule>
                <!--产品列表第几页-->
                <rule name="rPL">
                    <match url="^product/list-([0-9]*).html$" />
                    <action type="Rewrite" url="ProductList.aspx?page={R:1}" />
                </rule>               
                <!--产品类别列表-->
                <rule name="rPT">
                    <match url="^product/([A-Za-z0-9-]*)/$" />
                    <action type="Rewrite" url="ProductList.aspx?typeUrl={R:1}" />
                </rule>
                <!--产品类别列表第几页-->
                <rule name="rPTL2">
                    <match url="^product/([A-Za-z0-9-]*)/list-([0-9]*).html$" />
                    <action type="Rewrite" url="ProductList.aspx?typeUrl={R:1}&page={R:2}" />
                </rule>
                <!--产品详细-->
                <rule name="rPd">
                    <match url="^product/([A-Za-z0-9-]*)/([A-Za-z0-9-]+).html$" />
                    <action type="Rewrite" url="ProductDetail.aspx?typeUrl={R:1}&url={R:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

举个栗子:

在iis新建了一个叫做hello的站点,端口:8088

IIS7 伪静态 web.config 配置方法【详解】

站点目录新建一个index.html文件,内容 <h1>hello world</h1>

启动站点,浏览器输入:http://localhost:8088/

IIS7 伪静态 web.config 配置方法【详解】

ok,站点已经成功运行

打开站点目录,新建一个web.config 文件

IIS7 伪静态 web.config 配置方法【详解】
<?xml version="1.0"?>
<configuration>
<system.webServer>
        <rewrite>
            <rules>
                <!--我的规则-->
                <rule name="myrule">
                    <match url="^hello$" />
                    <action type="Rewrite" url="index.html" />
                </rule>
                <!--我的规则2-->
                <rule name="myrule2">
                    <match url="^jy/good$" />
                    <action type="Rewrite" url="jy/good.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

ps:安装 URL Rewrite 后才可以使用rewrite标签

 启动站点,打开浏览器,输入路由地址:http://localhost:8088/jy/good

然后会匹配到站点的 jy/good.html 文件,如下:

IIS7 伪静态 web.config 配置方法【详解】

good.html 内容为 <h1>Good</h1>

 浏览器显示:

IIS7 伪静态 web.config 配置方法【详解】

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/9891

(0)
凯影的头像凯影
上一篇 2023年10月23日 下午5:24
下一篇 2023年10月25日 下午4:20

相关推荐

  • 基于宝塔安装discuz

    前提条件 操作步骤 步骤一:配置PHP 安装扩展 TIP Discuz!Q 依赖于 fileinfo 和 exif 两个扩展运行,部署前需对 PHP 进行相关配置。以下操作将指导您安装fileinfo 和exif 扩展。 删除禁用函数 TIP Discuz!Q 需删除禁用的函数 puten…

    2023年7月31日
    1.5K00
  • Centos 7.9 宝塔面板下安装开源IDC机房资产管理系统-Racktables

    第一步:准备宝塔环境 根据racktables官方文档,选择合适版本,搭建环境。 第二步:安装racktables 1 官网下载(https://www.racktables.org/)racktables安装包,并上传到宝塔。 2 解压安装包,设置网站,创建数据库 3 浏览器完成安装 Please set ownership (chown) and/or …

    2022年12月22日
    2.3K00
  • Zabbix 首页提示PHP A session had already been started – ignoring session_start()

    zabbix打开首页报错,如下图 说时迟,那时快。 我赶紧百度了一下error ★ A session had already been started – ignoring session_start() 如果这后面没有任何文件,你需要这样去解决 如果出现 ★ A session had already been start…

    2023年4月28日
    1.3K00
  • Nginx配置及命令详解

    Nginx命令行 nginx -s 对应参数 信号 含义 stop TERM 强制关闭整个服务 null INT 强制关闭整个服务 quit QUIT 优雅地关闭整个服务 reopen USR1 重新打开日志记录 reload HUP 重新读取配置文件,并且优雅地退出老的worker nginx.conf重要的指令块 核心功能都在于http{}指令块里,ht…

    2022年6月17日
    1.6K00
  • 宝塔 shell 命令 自动重启nginx

    宝塔搭建网站,nginx总是意外宕机,可以通过宝塔计划任务定时重启服务 直接在计划任务里添下,Shell脚本如上图 代码如下 /etc/init.d/nginx restart 时间自己设定就可以 附上重启其它服务的命令 重启Mysql /etc/init.d/mysqld restart 重启PHP (根据安装PHP版本号做更改,例如:/etc/init.…

    2023年6月25日
    1.8K00

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信