2014-10-01 47 views
0

我正在尋找一些幫助使用正則表達式在IIS7上的301重定向。IIS7 301重定向正則表達式以連字符替換下劃線

我有鏈接指向像http://mydomain.co.uk/dir/colour_photo_copying.html這樣的頁面,我希望將這些文件重命名爲使用連字符而不是下劃線。

在一個接一個的基礎,我可以利用這樣做如下:

<location path="colour-photo-copying.html"> 
    <system.webServer> 
     <httpRedirect enabled="true" destination="colour_photo_copying.html" httpResponseStatus="Permanent" /> 
    </system.webServer> 
</location> 

唯一的問題是我有幾個這些並希望寫一個正則表達式規則,但我不知道如何做到這一點。

我遇到過這個頁面:IIS7 URL Rerwrite - how to replace all underscores with hyphens in a regex?但並不完全是我所希望的。

任何正則表達式的人在那裏幫助?

非常感謝您的任何建議。

回答

0

好吧,我發現這個解決方案,並認爲我會分享以防其他人查找它。

<rewrite> 
     <rules> 
      <rule name="replace underscore with hyphen" stopProcessing="true"> 
       <match url="^(.*)_(.*).*$" ignoreCase="false" /> 
       <action url="/{R:1}-{R:2}" type="Redirect" /> 
      </rule> 
     </rules> 
    </rewrite> 

如果有人覺得他們可以改善,請讓我知道。

謝謝, Jas