2013-06-24 18 views
0

我正在準備對我們的購物車進行重大改革,這將徹底改變網址的結構。對於它的價值,這是Magento 1.7。IIS7 URL重定向與正則表達式

一個例子網址是: {domain}/item/sub-domain/sub-sub-domain-5-16-7-16-/8083770?plpver=98&categid=1027&prodid=8090&origin=keyword

,重定向到{domain}/catalogsearch/result/?q=8083710

我的web.config是:

<?xml version="1.0" encoding="UTF-8"?> 
    <configuration> 
    <system.webServer> 
    <rewrite> 
    <rules> 
    <rule name="Magento Required" stopProcessing="false"> 
     <match url=".*" ignoreCase="false" />  <conditions> 
         <add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> <action type="Rewrite" url="index.php" /> 
    </rule> 
       <rule name="Item Redirect" stopProcessing="true"> 
        <match url="^item/([_\-a-zA-Z0-9]+)/([_\-a-zA-Z0-9]+)/([_\-a-zA-Z0-9]+)(\?.*)" /> 
        <action type="Redirect" url="catalogsearch/result/?q={R:3}" appendQueryString="true" redirectType="Permanent" /> 
        <conditions trackAllCaptures="true"> 
        </conditions> 
       </rule> 
    </rules> 
    </rewrite> 
     <httpProtocol allowKeepAlive="false" /> 
     <caching enabled="false" /> 
     <urlCompression doDynamicCompression="true" /> 
    </system.webServer> 
</configuration> 

現在看來重定向完全被忽略,即使在IIS GUI中,示例url傳遞了正則表達式測試。有沒有更好的方式來重定向或有什麼問題,我的web.config?

回答

0

原來的答案是here。在正則表達式中不能有問號,因爲IIS會將其視爲查詢字符串,並且需要在web.config的「條件」部分中捕獲它。

所以我只是把(\?.*)關正則表達式的結束,並補充說:

<conditions logicalGrouping="MatchAny" trackAllCaptures="true"> 
    <add input="{QUERY_STRING}" pattern=".*" /> 
</conditions>