正则表达式重写aspx?iid=
我正在尝试使用 ISAPI rewrite(mod_rewrite) 创建一个与此匹配的正则表达式:
www.website.com/product.aspx?iid=201
我已经尝试过:
^(.*)/product.aspx?iid=201
并且:
^(.*)/product\.aspx\?iid=201
两个表达式似乎都不匹配。
I'm trying to make a regular expression that matches this using ISAPI rewrite(mod_rewrite):
www.website.com/product.aspx?iid=201
I've tried:
^(.*)/product.aspx?iid=201
And:
^(.*)/product\.aspx\?iid=201
Neither expression seems to match it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的规则会将 (301) 从
domain.com/product.aspx?iid=201
重定向到domain.com/product/productname
您必须记住 -- Apache 的 mod_rewrite、Helicon ISAPI_Rewrite v3、IIS 7.x -
RewriteRule
指令(或 IIS 中的等效指令)仅适用于 URL 的“路径”部分。如果您需要使用域名、协议、服务器端口、查询字符串等 - 您必须使用RewriteCond
。上面的规则完全有效 - 我自己的一台服务器上确实有 Helicon ISAPI_Rewrite v3(IIS6,否则它将是 IIS7 和标准 URL 重写模块)。
如果您有任何疑问 - 请询问,但我很可能会在几个小时内回复 - 现在是凌晨 3 点:)
The rule below will redirect (301) from
domain.com/product.aspx?iid=201
todomain.com/product/productname
You have to keep in mind -- Apache's mod_rewrite, Helicon ISAPI_Rewrite v3, IIS 7.x -- the
RewriteRule
directive (or it's equivalent in IIS) only works with "path" part of URL. If you need to work with domain name, protocol, server port, query string etc -- you have to useRewriteCond
.The rule above is fully working -- I do have Helicon ISAPI_Rewrite v3 on one of my servers myself (IIS6, otherwise it would be IIS7 and standard URL Rewrite Module).
If you have any questions -- please ask, but most likely I will respond in few hours -- it's 3AM here :)
在这里工作:
http://www.regexplanet.com/simple/index.html
所以我希望这也能在 IIS 中工作
如果你使用的是 java,你会像这样转义你的第二个解决方案:
也许 IIS 喜欢这种转义方式(无法在此处测试)
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:
Maybe IIS likes that style of escaping (cannot test it here)