ISAPI重定向3过滤器301使用子域重定向

时间:2013-08-28 16:11:45

标签: regex redirect rewrite iis-6 isapi

我在编写用于IIS6的Helicon(许可版本)的ISAPI Rewrite 3规则方面非常新。我需要为“subdomain.domain.com”到“www.domain.com”为不同页面编写90多条规则,而且我对RegEx模式不是很熟悉。不幸的是,这些网站没有镜像,所以做一个简单的查询字符串追加将无法正常工作。

示例:将“http://subdomain.domain.com/products/product.aspx?id=42”重定向到“http://www.domain.com/productgroup/productinfo

我有一个很好的开始,但是我得到的最远的是让特定的页面重定向工作。我需要将其归结为某些页面的特定ID以不同方式重定向。目前,我将网页重定向到Google的代码(仅用于测试目的)是

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.102

RewriteEngine on
RewriteRule ^(subfolder.html)/?(.*)$ http://www.google.com/ [NC,R=301,L]

注意:我刚创建了一个包含以下页面的简单网站:   - /index.html   - /subfolder/subfolder.html   - /subfolder/subfolder2.html   - /subdir/subdir.html

根据之前的代码,“/ pubfolder / subfolder.html”重定向到Google,其他人正常显示该页面。出于测试目的,我一直试图追加“id = 1”重定向到YouTube,并将“id = 2”重定向到Facebook,这些都没有正在运行。代码是

RewriteRule ^(subfolder2.html\?id=1)$ http://www.youtube.com/ [NC,R=301,L]
RewriteRule ^(subfolder2.html\?id=2)$ http://www.facebook.com/ [NC,R=301,L]

我所需要的只是获得一个有效的模式,然后我可以从那里修改它以使其适用于其余页面。

感谢您的回复!

1 个答案:

答案 0 :(得分:1)

经过大量的反复试验,这就是我最终让它发挥作用的方式。

RewriteEngine on

RewriteCond %{QUERY_STRING} ^id=1 [NC]
RewriteRule products/product_detail.aspx http://www.newdomain.com/NewProductPage [NC,R=301,L]

根据我的理解,“RewriteCond”会查找该ID(在本例中)。 RewriteRule包含原始网址没有查询字符串(products / product_detail.aspx)和重定向的网址(http://www.newdomain.com/NewProductPage)。