首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用正则表达式进行IIS7 URL重定向

使用正则表达式进行IIS7 URL重定向
EN

Stack Overflow用户
提问于 2013-06-25 00:18:27
回答 1查看 1.5K关注 0票数 0

我正准备对我们的购物车进行一次大修,这将彻底改变urls的结构。无论它的价值是什么,这是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是:

代码语言:javascript
复制
<?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出了什么问题?

EN

回答 1

Stack Overflow用户

发布于 2013-06-25 03:38:10

事实证明答案是here。正则表达式中不能有问号,因为IIS将其视为查询字符串,并且需要在web.config的"conditions“部分中捕获它。

因此,我只是去掉了正则表达式的末尾的(\?.*),并添加了:

代码语言:javascript
复制
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
    <add input="{QUERY_STRING}" pattern=".*" />
</conditions>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17280210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档