2012-04-14 7 views
12

私はWindows Server 2008とIIS7.5の共有ホスティングプランを持っており、Microsoftリライトモジュールがインストールされ、有効になっています。マイクロソフトのリライトモジュール - URLを強制的にURLにするまたはURLからwwwを削除する

<rewrite> 
    <rules> 
     <rule name="myRule" patternSyntax="Wildcard"> 
      <!--Rewriting code--> 
     </rule> 
    </rules> 
</rewrite> 

だから、どのようにMicrosoftは、モジュールを書き換えてwww.mydomain.com/everywhere-in-site/my-page.htmlするmydomain.com/everywhere-in-site/my-page.htmlをリダイレクトするには?

www.mydomain.com/everywhere-in-site/my-page.htmlをmydomain.com/everywhere-in-site/my-page.htmlにリダイレクトする場合はどうすればよいですか?

<rewrite> 
    <rules> 
    <rule name="Remove WWW prefix" stopProcessing="true"> 
     <match url="(.*)" ignoreCase="true" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^www\.yourdomain\.com$" /> 
     </conditions> 
     <action type="Redirect" url="http://yourdomain.com/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

そして、周りの他の方法(あなたがいることを好む場合)リダイレクトするには:あなたは可能性がディそれを次のコードスニペットのようにドメインからWWWを削除し、「独自ドメイン」にリダイレクトするように

答えて

32

WWWと1対非WWW:

<rewrite> 
    <rules> 
    <rule name="Add WWW prefix" stopProcessing="true"> 
     <match url="(.*)" ignoreCase="true" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" /> 
     </conditions> 
     <action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

redirectType="Permanent"はもちろん任意であるが、SEOとほとんどのシナリオのために私はそれをお勧めします。

も、これらのSO質問/回答を参照してください。

+2

この答えはSOどうあるべきかの縮図。 Martinに感謝します。 – pimbrouwers

関連する問題