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

相关推荐

  • NGINX的基本编译安装部署

    yum自动安装,不支持自由扩展第三方功能 源码编译安装,可以指定安装路径,并支持自由安装模块 安装前准备 安装GCC编译环境 安装模块依赖 Nginx支持的功能模块需要有第三方的库支持,例如gzip的zlib库,rewrite重写需要的pcre库,HTTPS需要的openssl库等等。 如果出现报错 可以在后面添加命令 –setopt=prote…

    2022年6月17日
    48010
  • PHP编译安装时常见错误及解决办法

    1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. *27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. …

    2023年4月28日
    20000
  • Nginx 代理 MySQL 连接,并限制可访问IP

    1.前言 我们的生产环境基本上都部署在云服务器上,例如应用服务器、MySQL服务器等。如果MySQL服务器直接暴露在公网,就会存在很大的风险,为了保证数据安全,MySQL服务器的端口是不对外开放的。 好巧不巧,线上业务遇到bug了,开发的小伙伴需要远程连接MySQL来查看数据,那应该怎么办呢? 我们可以通过Nginx代理(“跳板机”)来进行连接。 2.Ngi…

    2023年8月21日
    14000
  • 解决Composer Installing dependencies from lock file

    1、问题描述 2、原因 这是因为不匹配composer.json要求的版本。提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下应该也是可以运行的,composer可以设置忽略版本匹配。 3、解决方案 composer install –ignore-platform-reqs 或者 composer update -…

    2023年2月14日
    27600
  • IIS发布网站时报403错误的所有原因及解决方案

    在使用IIS的时候,如果遇到403相关的错误,我们往往束手无策,不知道是什么权限的原因。现总结如下,供以后参考。 1、403.1 – 执行访问被禁止 没有足够的执行权限,例如你访问的index.php文件,但是该文件并没有执行权限,那么浏览器在访问时就会出现该错误,然后你就需要去修改目录的权限了 2、403.2 – 读访问被禁止验证是…

    2022年6月21日
    1.0K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信