2017-09-15 1 views
0

URLに "www"が付加されていないRewriteRuleがあります。IIS RewriteRules

<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true"> 
    <match url="*" /> 
    <conditions> 
    <add input="{HTTP_HOST}" pattern="www.example.com" negate="true" /> 
    </conditions> 
    <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" /> 
</rule> 

問題は、この書き換えルールを適用したくない別のインバウンドドメイン(www.example2.com)です。私は次のことがうまくいくと思います。

<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true"> 
    <match url="*" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{HTTP_HOST}" pattern="www.example.com" negate="true" /> 
    <add input="{HTTP_HOST}" pattern="www.example2.com" negate="true" /> 
    </conditions> 
    <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" /> 
</rule> 

しかし、無視されているようです。助言がありますか?ありがとう!

答えて

0

このルールで行うことができます。それが唯一のドメインexample.comため、WWWを追加すると、他のすべてのドメインを無視します:

<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true"> 
    <match url="*" /> 
    <conditions> 
    <add input="{HTTP_HOST}" pattern="^example.com$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" /> 
</rule> 
0

ビクターが道のほとんどを私を得ました。ありがとう!

<rule name="Add www" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^example.com$" /> 
     </conditions> 
     <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" /> 
    </rule> 

patternSyntaxは、デフォルトの正規表現値でなければなりません。つまり、URLパターンを変更する必要があり、バックトラック式はゼロベースです。