Asp.net IIS重写规则-如何包含根文档

Asp.net IIS重写规则-如何包含根文档,asp.net,iis,url-rewriting,Asp.net,Iis,Url Rewriting,我有一个将HTTPS重定向到HTTP的简单IIS规则: <rule name="HTTPS" enabled="true" stopProcessing="true"> <match url=".*\.(asp)$" ignoreCase="false" /> <conditions> <add input="{HTTPS}" pattern="on" /> <add input="{REQUE

我有一个将HTTPS重定向到HTTP的简单IIS规则:

<rule name="HTTPS" enabled="true" stopProcessing="true">
    <match url=".*\.(asp)$" ignoreCase="false" />
    <conditions>
        <add input="{HTTPS}" pattern="on" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/ecards/user*" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
我不希望将匹配URL设置为:

<match url="(.*)" />


因为其他非
.asp
文件会被重写。

在规则中包含目录的一种方法是排除所有其他内容

假设其他所有内容都有一个文件扩展名(例如
.php
.css
.js
,等等),您可以否定路径中包含
的所有输入

我对您的代码做了一些修改,以便在本地制作一个工作演示(我没有HTTPS本地测试,因此我没有重定向到HTTP,而是将其设置为重定向到
About.aspx
),这两条规则是:

<rule name="HTTPS" enabled="true" stopProcessing="true">
    <match url=".*\.(asp)$" ignoreCase="false" />
    <action type="Redirect" url="/About.aspx" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="NEWRULE" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{REQUEST_URI}" negate="true" pattern=".*\.(.)$" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/About*" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="/About.aspx" appendQueryString="true" redirectType="Permanent" />
</rule> 

出于对@Tasos K的兴趣,我试图添加另一条规则来强制https,例如*。可能吗?您提供的规则将强制除ecards/user*之外的所有HTTPS转换为HTTP,但我还需要强制*转换为HTTPS。条件
应该可以防止这种情况,对吗?我在我的演示中添加了这个规则和URL
http://localhost:51801/ecards/user/ddd
http://localhost:51801/ecards/user-某些内容
未重定向。可能是web.config中的另一条规则导致了这个问题。谢谢@Tasos K。我遇到的问题是,在重定向正常工作之前,我的整个网站都被谷歌以HTTPS的形式编制了索引。现在我需要将所有HTTPS重定向到HTTP,除了ecard/user*,它现在可以使用您的规则正常工作。但如果用户转到HTTP..ecard/user*我需要它重定向到HTTPS,但仅限于这些页面,而不是其他任何页面。例如,这需要通过一个不同的规则重定向到HTTPS版本,同时将HTTPS保留到HTTP规则中。关于谷歌及其索引,考虑使用Meta <代码> <代码>,并将HTTP链接放在那里(参见)。几周后,谷歌索引将使用你提供的链接。同样,对于CSS和JS文件,使用
/
前缀代替
http://
https://
(请参阅)。这些提示不适用于IIS重写规则,但它们可能会帮助您通过较少的重写规则来解决问题。谢谢,我将查看索引问题的规范选项。关于重写规则,有没有两个规则可以共存的方法,一个用于HTTPS到HTTP,正如您所写的,另一个用于在一段时间内强制从HTTP重定向到HTTPS目录,因为我的站点上还有其他文件夹,我想强制使用HTTPS,例如admin文件夹等等,例如jimpix.co.uk/admin/
<rule name="HTTPS" enabled="true" stopProcessing="true">
    <match url=".*\.(asp)$" ignoreCase="false" />
    <action type="Redirect" url="/About.aspx" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="NEWRULE" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{REQUEST_URI}" negate="true" pattern=".*\.(.)$" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/About*" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="/About.aspx" appendQueryString="true" redirectType="Permanent" />
</rule> 
<rule name="IncludeDirectories" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{REQUEST_URI}" negate="true" pattern=".*\.(.)$" ignoreCase="true" />
        <add input="{HTTPS}" pattern="on" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/ecards/user*" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>  
<add input="{REQUEST_URI}" negate="true" pattern=".*\.(.)$" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern=".*\.(php|css|js|jpg|gif|png)$" ignoreCase="true" />
<rule name="HTTPS2Admins" enabled="true" stopProcessing="true">
    <match url="/ecards/user(.*)" />
    <conditions>
        <add input="{HTTP}" pattern="on" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/ecards/user{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>