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

相关推荐

  • Linux 宝塔部署 ASP.NET Core 应用

    第一步,发步应用 我这是一个API 应用和 MVC 应用 设置,服务器上要运行的端口 API 端口5000 MVC 端口5001 打包文件夹,发步 1、桌面新建俩个文件夹 2、右键项目发步,选中iis 目标位置选择刚刚桌面上创建的API文件夹 MVC 同理,这里不做演示 第二步、安装LInux ASP.NET Core 运行时环境 1、连接服务器 2、执行以…

    2023年3月8日
    1.6K00
  • OpenSSL自签证书生成

    一 背景 我们的mqtt broker服务,使用了SSL自签证书,可以提高mqtt连接安全性。 二 生成自签证书 在Centos7下生成,有效时长:100年

    2023年3月9日
    82000
  • 解决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日
    99600
  • IIS怎么设置应用程序池自动回收

    1、打开 IIS 管理控制台,双击“应用程序池”文件夹。 2、右击适当的应用程序池,然后单击“高级设置”。出现应用程序池的属性对话框。 3、默认回收是有一个固定时间间隔的,但是太长了 4、点击特定时间后面的三个点 5、然后点击添加按钮,接着在Value里面设置时间点,如下图所示 6、最后可以设置多个时间点,如下图所示

    2022年8月9日
    1.9K00
  • IIS php网站 无法在<fastCGI>应用程序配置中找到<handler> scriptProcessor

    打开后会发现,根目录里面会自动生成的多出来的这个文件【web.config】直接删除掉,然后再去刷新一下你的页面就可以正常显示了 改你的路径。

    2023年4月6日
    90400

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信