2014-12-11 81 views
0

我有一個重寫地圖〜100舊的URL到新的URL行:如何在使用重寫映射時忽略.aspx擴展名?

<rewriteMaps> 
    <rewriteMap name="OldSiteRewriteMap" defaultValue=""> 
    ... 
    <add key="https://stackoverflow.com/a/b/oldpage" value="/x/y/newpage" /> 
    ... 
    </rewriteMap> 
</rewriteMaps> 

我有一個使用該地圖來重定向URL的(我們剛剛推出了一個新的網站重寫規則和我們的映射從舊網站對相應的URL網址的新網站):

<rule name="Redirect old site URLs"> 
    <match url=".*" /> 
    <conditions> 
    <add input="{OldSiteRewriteMap:{PATH_INFO}}" pattern="(.+)" /> 
    </conditions> 
    <action type="Redirect" url="{C:1}" redirectType="Permanent" appendQueryString="false" /> 
</rule> 

當我訪問http://example.com/a/b/oldpage(舊網站網址)我重定向到http://example.com/x/y/newpage - 太棒了!但是當我訪問http://example.com/a/b/oldpage.aspx -note .aspx擴展名時 - 我不會重定向。

如何告訴我的重寫規則在嘗試使用重寫映射映射URL時忽略「.aspx」擴展名?

回答

0

一位同事提出以下建議 - 在「匹配url」中使用正則表達式來捕獲除可能結尾的「.aspx」之外的所有內容,然後將捕獲傳遞給重寫映射以代替PATH_INFO或任何其他服務器變量。似乎工作得很好。

<rule name="Redirect old site URLs"> 
     <match url="^(.+?)(\.aspx)?$" /> 
     <conditions> 
     <add input="{OldSiteRewriteMap:{R:1}}" pattern="(.+)" /> 
     </conditions> 
     <action type="Redirect" url="{C:1}" redirectType="Permanent" appendQueryString="false" /> 
    </rule>