2012-11-07 33 views
0

我想(和epicly不及格)找出必要的規則,以達到以下永久301重定向:IIS7 URL 301重定向文件夾和域

www.mysite.com     > mysite.com 
mysite.com/oldfolder    > mysite.com 
www.mysite.com/oldfolder   > mysite.com 
mysite.com/oldfolder/old-file  > mysite.com/old-file 
www.mysite.com/oldfolder/old-file > mysite.com/old-file 

如果有人用IIS7重寫模塊的理解可以幫助我,我會非常感激!

+0

對於上下文,我們將從一個子目錄中的wordpress博客轉移到根目錄中,但也想從規範化子域重定向到根目錄 – DannyT

回答

0

以供將來參考和其他人在這裏做了類似的事情是我們最終的總規則使用:

<rewrite> 
     <rules> 
      <!--To always remove trailing slash from the URL--> 
      <rule name="Remove trailing slash" stopProcessing="true"> 
       <match url="(.*)/$" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Redirect" redirectType="Permanent" url="{R:1}" /> 
      </rule> 
      <!-- redirects blog/2012/10/post to /post. --> 
      <rule name="Redirect blog with dates to root" stopProcessing="true"> 
       <match url="^blog/([0-9]+)/([_0-9]+)/(.*)" /> 
       <conditions> 
        <add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" /> 
       </conditions> 
       <action type="Redirect" url="http://{C:0}/{R:3}" redirectType="Permanent" /> 
      </rule> 
      <!-- redirects blog/post to /post. --> 
      <rule name="Redirect blog to root" stopProcessing="true"> 
       <match url="^blog/(.*)" /> 
       <conditions> 
        <add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" /> 
       </conditions> 
       <action type="Redirect" url="http://{C:0}/{R:1}" redirectType="Permanent" /> 
      </rule> 
      <!-- redirects case-studies/case-study to /case-study. --> 
      <rule name="Case studies redirect." stopProcessing="true"> 
       <match url="^case-studies/(.*)" /> 
       <conditions> 
        <add input="{HTTP_HOST}" pattern="^(www\.)?mydomain.com$" /> 
       </conditions> 
       <action type="Redirect" url="http://{C:0}/{R:1}" redirectType="Permanent" /> 
      </rule> 
      <!-- for SEO the www is stripped from the URL. --> 
      <rule name="Canonical host name."> 
       <match url="(.*)" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{HTTP_HOST}" pattern="^mydomain\.com$" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="http://mydomain.com/{R:1}" /> 
      </rule> 
      <!-- removes index.php from the URL. --> 
      <rule name="wordpress" patternSyntax="Wildcard"> 
       <match url="*"/> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
       </conditions> 
       <action type="Rewrite" url="index.php"/> 
      </rule> 
     </rules> 
    </rewrite> 
0

你應該只需要添加一個規則,像這樣:

請求的URL: 匹配模式

使用:正則表達式

模式: oldfolder

忽略大小寫:真

動作類型:重定向

重定向URL:HTT://www.mysite.com

追加查詢字符串:虛假 重定向類型301