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

相关推荐

  • 使用Openssl 自签发IP证书

    使用Openssl 自签发IP证书 日常交付项目中,总是有这样的场景,再使用一些融合通讯的业务时,需要HTTPS 环境,那就涉及到SSL 证书的签发 考虑到项目成本的问题,往往都是本地自签发IP 证书使用;使用openssl生成根证书,签发服务端证书,安装根证书使浏览器信任自签证书。 创建证书脚本:ssl.sh 证书脚本内容: 签发证书 签发好的证书 安装根…

    2023年5月26日
    1.3K00
  • 安装悟空crm的几种报错及解决办法

    1、浏览器访问的时候,界面只弹出“悟空软件”四个字 只需要修改成这样http://localhost/index.html 再访问,就可以到登录界面了 – – – 2.、输入用户名和密码之后弹出“网络错误,请检查您的网络” 先测试你现在的网络是否可用,其次就是你的用户名不存在或者输入错误 – – &…

    2022年8月16日
    5.4K00
  • 网站期末架构

    用户向 发起访问请求 负载均衡器(Nginx 七层负载均衡区分移动端和PC端,LVS四层负载均衡可以处理高并发请求)将请求进行分发 Tomcat等web服务器根据请求内容,进行任务分发 如果请求内容需要快速响应,则将请求发送到MenCache、Redits等缓存数据库,然后将修改内容更新到SQL数据库集群 如果是普通的读写请求,则进行读写分离操作,读取和写入…

    2022年6月18日
    1.1K00
  • 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日
    93200
  • 宝塔部署java项目

    进入宝塔官方网站 url地址 https://www.bt.cn/download/linux.html 下滑看到安装命令(我这边使用的是centos7.8)复制相应脚本命令 Centos安装脚本 输入复制的命令 等待安装宝塔面板,粘贴点击回车即可 中间会输入一次确认是否安装 输入 y 回车 安装需要一小段时间,最后当出现有宝塔面板地址和账号密码的时候证明安…

    2023年4月3日
    91800

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信