Multiple IIS7 URL Rewrite rules
I'm trying to write IIS7 URL Rewrites rules that do two things:
- If a request is to http, force it to https
- If the url has a "www" in it, remove it and redirect to different url
In both cases I want to redirect to h开发者_如何学编程ttps://my.domain.com (substitute for real domain name)
I have no problem with the http to https rule. Also, the case of http://www.my.domain.com to https://my.domain.com also works. However, the one case I have not been able to get to work is when the original request is to https://www.my.domain.com
Here's what I have now:
<rule name="r2" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT}" pattern="443" negate="false" matchType="Pattern" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" />
</conditions>
<action type="Redirect" url="https://my.domain.com" />
</rule>
<rule name="r1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT}" pattern="443" negate="true" matchType="Pattern" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" />
</conditions>
<action type="Redirect" url="https://my.domain.com" />
</rule>
Any idea of what I need to change to get https://www.my.domain.com to redirect to https://my.domain.com ?
This may work for you
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="https://mydomain.com$"/>
</conditions>
<action type="Redirect" url="https://www.mydomain.com/{R:1}" redirectType="Permanent"/>
</rule>
Try this It is working for me
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="permalink">
<match url="article/(\D+)(\/)*$" />
<action type="Rewrite" url="http://mywebsite.com/article.aspx?id={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
精彩评论