0

我正在尝试使用 ISAPI rewrite(mod_rewrite) 制作一个与此匹配的正则表达式:

www.website.com/product.aspx?iid=201

我试过了:

^(.*)/product.aspx?iid=201

和:

^(.*)/product\.aspx\?iid=201

这两种表达似乎都不匹配。

4

2 回答 2

1
^(.*)/product.aspx\?iid=201

works here:

http://www.regexplanet.com/simple/index.html

So I would expect that to also work in IIS

If you were using java, you would escape your second solution like this:

"^(.*)/product\\.aspx\\?iid=201"

Maybe IIS likes that style of escaping (cannot test it here)

于 2011-06-22T21:18:25.807 回答
1

下面的规则会将 (301) 从重定向domain.com/product.aspx?iid=201domain.com/product/productname

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^iid=201 [NC]
RewriteRule ^product\.aspx$ /product/productname [NC,R=301,L]

您必须记住——Apache 的 mod_rewrite、Helicon ISAPI_Rewrite v3、IIS 7.x——该RewriteRule指令(或 IIS 中的等效指令)仅适用于 URL 的“路径”部分。如果您需要使用域名、协议、服务器端口、查询字符串等 - 您必须使用RewriteCond.

上面的规则完全有效——我自己的一台服务器上确实有 Helicon ISAPI_Rewrite v3(IIS6,否则它将是 IIS7 和标准 URL 重写模块)。

如果您有任何问题——请提问,但我很可能会在几个小时内回复——现在是凌晨 3 点 :)

于 2011-06-23T02:08:35.277 回答