2012-05-15 77 views
0

很抱歉的模糊標題,這個問題太複雜的短語來概括...IIS重寫規則跳過即使模式匹配

我試圖設置以下重定向規則:

  1. blog.mydomain.net/en/something:重定向到www.mydomain.com/something
  2. blog.mydomain.net/fr/something:重定向到www.mydomain.fr/something
  3. blog.mydomain.net/*:重定向到www.mydomain.com

規則3正在工作,但規則1和規則2似乎被跳過,所以總是應用規則3。下面是我的web.config規則:

<!-- Canonicalize mydomain.com to www.mydomain.com --> 
<rule name="CanonicalHostNameRule_en" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTP_HOST}" pattern="^mydomain\.com$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.mydomain.com/{R:1}" /> 
</rule> 

<!-- Canonicalize mydomain.fr to www.mydomain.fr --> 
<rule name="CanonicalHostNameRule_fr" enabled="true" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTP_HOST}" pattern="^mydomain\.fr$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.mydomain.fr/{R:1}" /> 
</rule> 

<!-- Redirect blog.mydomain.net/en/something to www.mydomain.com/something --> 
<rule name="RedirectBlog_en" enabled="true" stopProcessing="true"> 
    <match url="^/en(/.*)?$" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.mydomain.com/{R:1}" /> 
</rule> 
<!-- Redirect blog.mydomain.net/fr/something to www.mydomain.fr/something --> 
<rule name="RedirectBlog_fr" enabled="true" stopProcessing="true"> 
    <match url="^/fr(/.*)?$" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.mydomain.fr/{R:1}" /> 
</rule> 

<!-- Redirect blog.mydomain.net/* to www.mydomain.com --> 
<rule name="RedirectBlog_other" enabled="true" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTP_HOST}" pattern="^blog\.mydomain\.net$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.mydomain.com/" /> 
</rule> 

<!-- Wordpress-specific rules --> 
... 

我不明白爲什麼規則RedirectBlog_enRedirectBlog_fr會被跳過;我測試了正則表達式,它們工作正常。

任何人都可以發現問題嗎?


編輯:如果我禁用第三規則(RedirectBlog_other),那麼規則1和2,做工精細......這怎麼可能,因爲規則1和2規則3之前執行?

回答

1

好的,我明白了!

首先,事情並沒有像我想的那樣發生;規則1和2分別是而不是當我禁用規則3時:我仍然被重定向到我的實際域,但這是通過Wordpress完成的,而不是由我的規則完成的。

其次,我的匹配URL的模式是錯誤的:前導'/'是而不是包含在輸入中,所以我的規則根本不匹配。