簡體   English   中英

使用Regex進行IIS7 URL重定向

[英]IIS7 URL Redirect with Regex

我正在准備對購物車進行大修,這將完全改變網址的結構。 對於它的價值,這是對Magento 1.7。

示例網址為: {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通過了regex測試,似乎也完全忽略了重定向。 是否有更好的重定向方法,或者我的web.config有問題?

原來答案就在這里 正則表達式中不能包含問號,因為IIS將其視為查詢字符串,並且需要在web.config的“條件”部分中捕獲它。

所以我只是把(\\?.*)從正則表達式的末尾刪除,並添加:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM