2016-05-18 9 views
0

Stack Overflowでよく似た質問がありますが、見つからないこれらの3つのリダイレクトルールが一緒に機能するのに役立ちます。IISで、www、https、およびファイル拡張子がないURLにすべてのURLを転送するにはどうすればいいですか?

私はこのフォーマットに私のすべてのURLを転送しようとしています:

https://example.com/page 

私は、HTTPSを必要とする、私はWWWをしたくない、と私は、HTMLやASPXの拡張子はなりたくありません可視。ここまで私がこれまで持っていたことがあります。 Chromeではリダイレクトが多すぎると言いますが、どのようにこれらのルールを統合しますか?

<rewrite> 
     <rules> 
      <clear /> 

      <rule name="RewriteHTML"> 
       <match url="(.*)" /> 
       <conditions logicalGrouping="MatchAll"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="{R:1}.html" /> 
      </rule> 

      <rule name="Redirect www to non-www" enabled="true" stopProcessing="true"> 
       <match url="(.*)\.html$" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="http://example.com/{R:1}" redirectType="Permanent"/> 
      </rule> 

      <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true"> 
       <match url="(.*)\.html$" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{HTTPS}" pattern="^OFF$" /> 
       </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/> 
      </rule> 

      <rule name="RemoveExtension" stopProcessing="true"> 
       <match url="(.*)\.html$" /> 
       <action type="Redirect" url="{R:1}" redirectType="Permanent" /> 
      </rule> 

     </rules> 
    </rewrite> 

答えて

0

パターンやルールオーダー、stopProcessingコマンドなどを使って遊んだ後、ついにそれを理解しました。リダイレクトループはもうありません!私は実際に私が求めていたものとそれ以上を考え出した。

  1. は、ルートドメイン
  2. からのindex.htmlを削除した非WWW
  3. にWWWをリダイレクトし、末尾が
  4. は、URLが常に小文字
  5. がHTTPをリダイレクトしますスラッシュ削除:// httpsに://
  6. URLが.html拡張子なしで動作するようにします。
  7. .html拡張子なしのURLにリダイレクト

マイコード:ここで

<rules>   
    <!-- index.html Redirect -->  
    <rule name="index.html Redirect" enabled="true"> 
     <match url="^(.*\/)*index\.html$" /> 
     <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" /> 
     </conditions> 
     <action type="Redirect" url="{R:1}" redirectType="Permanent" /> 
    </rule> 

    <!-- Redirect WWW to non-WWW --> 
    <rule name="Redirect WWW to non-WWW" enabled="true"> 
     <match url="(.*)" /> 
     <conditions> 
      <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="http://example.com/{R:1}" /> 
    </rule> 

    <!-- Remove Trailing Slash --> 
    <rule name="Remove Trailing Slash" enabled="true"> 
     <match url="(.*)/$" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="{R:1}" /> 
    </rule> 

    <!-- Make URL Lower Case --> 
    <rule name="Make URL Lower Case" enabled="true"> 
     <match url="[A-Z]" ignoreCase="false" /> 
     <action type="Redirect" url="{ToLower:{URL}}" /> 
    </rule> 

    <!-- Redirect To HTTPS --> 
    <rule name="Redirect To HTTPS" enabled="true"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
      <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 

    <!-- Redirect To URL With No Extension --> 
    <rule name="Redirect To URL With No Extension" enabled="true"> 
     <match url="(.*)\.(html)" /> 
     <action type="Redirect" url="{R:1}" /> 
    </rule>    

    <!-- Rewrite URL For No Extension --> 
    <rule name="Rewrite URL For No Extension" enabled="true" stopProcessing="false"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="{R:0}.html" /> 
    </rule> 
</rules> 

はルールがIIS URL書き換えモジュールにどのように見えるかです:

URL Rewrite Rule Details

関連する問題