I have a website setup in IIS 6, let's say it's called http://www.this.com.
我在IIS 6中设置了一个网站,假设它叫做http://www.this.com。
I have setup a redirection for this website to http://www.that.com which maintains the directory structure and query parameters as follows:
我已经为这个网站设置了一个重定向到http://www.that.com,它维护目录结构和查询参数如下:
http://www.that.com$S$Q - using the option "The exact URL entered above"
http://www.that.com$S$Q - 使用“上面输入的确切网址”选项
This works great, whenever someone requests, for example:
每当有人请求时,这都很有用,例如:
http://www.this.com/subfolder/page.aspx?Id=1
then they end up at:
然后他们最终:
http://www.that.com/subfolder/page.aspx?Id=1
Now, I have one page, actually a handler, http://www.this.com/image.axd, which I do not want to redirect.
现在,我有一个页面,实际上是一个处理程序,http://www.this.com/image.axd,我不想重定向。
What is the syntax for that? I've read the Redirection Using Wildcards section here, but I can't work out how to do what seems to be something straight forward.
那是什么语法?我在这里阅读了使用通配符重定向部分,但我无法弄清楚如何做一些看似直截了当的事情。
Note that image.axd is a handler so I can't just "right click" on it and set the redirection properties as it doesn't physically exist.
请注意,image.axd是一个处理程序,所以我不能只是“右键单击”它并设置重定向属性,因为它实际上不存在。
I also have a couple of other pages in subfolders which I do not want to redirect, for example:
我还在子文件夹中有几个其他页面,我不想重定向,例如:
http://www.this.com/subfolder/donotredirectthispage.aspx
Any help would be appreciated.
任何帮助,将不胜感激。
Edit: A couple of people have mentioned using ISAPI_Rewrite, for which I'm grateful, but I really don't want to introduce another complexity into the website configuration. IIS seems to imply I can acheive what I want using the ! and 0 through 9 variables.
编辑:有几个人提到过使用ISAPI_Rewrite,我很感激,但我真的不想在网站配置中引入另一个复杂性。 IIS似乎暗示我可以实现我想要的东西!和0到9个变量。
Is it really not possible to do this using IIS?
使用IIS真的不可能这样做吗?
My current workaround is to set the redirection properties on ALL folders and pages that I want to redirect except those I do not, but this is a management nightmare.
我目前的解决方法是在我想要重定向的所有文件夹和页面上设置重定向属性,但我没有,但这是一个管理噩梦。
3 个解决方案
#1
1
You could implement a custom error page for the page not found
error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.
您可以为页面未找到错误(404)实现自定义错误页面,为您执行重定向。您将关闭IIS中的重定向。在自定义错误页面中构建重定向的逻辑。然后配置您的网站,以便404错误重定向到您的错误页面。
#2
0
If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.
如果您可以在IIS服务器上安装软件,我建议您使用工具重写您的请求URL。
For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.
对于IIS 6.0,我使用了ISAPI_Rewrite,它运行得非常好。它重量轻,可配置。有一个免费的“精简版”版本,将支持您的要求。
You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.
您可以使用包含与HTTP请求匹配的规则的文本文件来配置程序,然后在匹配规则时写入要执行的操作。您的实例可能需要一般的重定向规则(类似于IIS中的规则)和规则。
#3
0
You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.
您应该研究使用标头重写模块的可能性,例如ISAPI_rewrite。有一个免费的“精简版”可供您满足需求。
What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.
这可以为您做什么如下:在服务器上执行实际页面之前,将根据一组可配置的规则重写请求标头(或发出HTTP 301/302重定向)。底层服务器看到剩余的请求,好像客户端确实以这种方式创建它们。
The following rules would leave image.axd
requests alone, while redirecting everything else.
以下规则将单独留下image.axd请求,同时重定向其他所有内容。
# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]
# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]
#1
1
You could implement a custom error page for the page not found
error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.
您可以为页面未找到错误(404)实现自定义错误页面,为您执行重定向。您将关闭IIS中的重定向。在自定义错误页面中构建重定向的逻辑。然后配置您的网站,以便404错误重定向到您的错误页面。
#2
0
If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.
如果您可以在IIS服务器上安装软件,我建议您使用工具重写您的请求URL。
For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.
对于IIS 6.0,我使用了ISAPI_Rewrite,它运行得非常好。它重量轻,可配置。有一个免费的“精简版”版本,将支持您的要求。
You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.
您可以使用包含与HTTP请求匹配的规则的文本文件来配置程序,然后在匹配规则时写入要执行的操作。您的实例可能需要一般的重定向规则(类似于IIS中的规则)和规则。
#3
0
You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.
您应该研究使用标头重写模块的可能性,例如ISAPI_rewrite。有一个免费的“精简版”可供您满足需求。
What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.
这可以为您做什么如下:在服务器上执行实际页面之前,将根据一组可配置的规则重写请求标头(或发出HTTP 301/302重定向)。底层服务器看到剩余的请求,好像客户端确实以这种方式创建它们。
The following rules would leave image.axd
requests alone, while redirecting everything else.
以下规则将单独留下image.axd请求,同时重定向其他所有内容。
# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]
# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]