简体   繁体   English

多个IIS7 URL重写规则

[英]Multiple IIS7 URL Rewrite rules

I'm trying to write IIS7 URL Rewrites rules that do two things: 我正在尝试编写IIS7 URL Rewrites规则,该规则可做两件事:

  • If a request is to http, force it to https 如果请求是http,则将其强制为https
  • If the url has a "www" in it, remove it and redirect to different url 如果网址中包含“ www”,请将其删除并重定向到其他网址

In both cases I want to redirect to https://my.domain.com (substitute for real domain name) 在两种情况下,我都想重定向到https://my.domain.com (用真实域名代替)

I have no problem with the http to https rule. 我的http to https规则没有问题。 Also, the case of http://www.my.domain.com to https://my.domain.com also works. 同样,从http://www.my.domain.comhttps://my.domain.com的情况也适用。 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 但是,我无法上班的一种情况是原始请求发送到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 ? 我需要更改以使https://www.my.domain.com重定向到https://my.domain.com的任何想法?

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>

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM