2016-08-10 10 views
0

HTTPS(現在動作している)とwww(既にURLにない場合)にリダイレクトできる必要があります。URL書き換え - Web.config - HTTPSとwww

URLがでない場合、にはwwwがあり、正常に動作します。 URL wwwを持っていない場合しかし、それは、そのような私はハードコードにドメインをしたくない、とHTTPHOSTまたは同等のものを使用したいと思いますhttps://www.www.domain.com

注意として、追加のwwwをリダイレクトし、追加します。

現在の書き換えルール:この正規表現になってしまった

<rule name="Redirect to HTTPS" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    <rule name="WWW Rewrite" enabled="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
     </conditions> 
     <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> 
    </rule> 

答えて

-1

から^((?!www).)*[a-zA-Z0-9]+$

は、私はまた、IISと変更に行かなければならなかった「パターンと一致しません」「パターンにマッチします"

<rule name="Redirect to HTTPS" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    <rule name="WWW Rewrite" enabled="true" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAny"> 
     <add input="{HTTP_HOST}" pattern="^((?!www).)*[a-zA-Z0-9]+$" /> 
     </conditions> 
     <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> 
    </rule> 
+1

こうすると、http://hostwithoutwww.com URLで二重リダイレクトを実行しているので、 "Httpへのリダイレクト"前の "WWW書き換え"ルールは、 –

関連する問題