如何将IIS服务器中的特定端口重定向到其他端口 [英] How do I redirect a specific port in the IIS server to an other port
问题描述
我的URL重写规则仅适用于IIS中的端口80.
My URL Rewrite rule only works for port 80 in IIS .
重写适用于: http://localhost:80 -> 该重写适用于: http://localhost:80/redirect -> http://localhost:8100
The rewrite works for : http://localhost:80/redirect --> http://localhost:8100
该重写不适用于: http://localhost:8080 -> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080 --> http://localhost:8100
该重写不适用于: http://localhost:8080/redirect -> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080/redirect --> http://localhost:8100
我的web.config如下:
My web.config is following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" />
<rewrite>
<rules>
<rule name="Redirect to port 8100" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT}" pattern="^8100$" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}:8100/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config仅可在默认的http端口80/443上运行,而不能在特定的端口上工作.
The web.config is only working on default http port 80/443 but not for an specific port.
要使用所有端口,必须在web.config中进行哪些更改?
Which changes has to be made in the web.config for working with all ports?
推荐答案
主要问题是变量 {HTTP_HOST}
,该变量已经包含 PORT
信息.
The main problem is the variable {HTTP_HOST}
which already contains the PORT
information.
要解决此问题,您需要调整两件事:
To solve this issue you need to adjust two things:
- 在其中扩展匹配模式
- 设置正确的重定向地址
我对您的 web.config
进行了调整,以查看它如何与您的示例配合使用:
I adjusted your web.config
to see how it should work with your example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" />
<rewrite>
<rules>
<rule name="Redirect to port 8100" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" >
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="http://{C:1}:8100/{R:0}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这篇关于如何将IIS服务器中的特定端口重定向到其他端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!