如何将 IIS 服务器中的特定端口重定向到其他端口 [英] How do I redirect a specific port in the IIS server to an other port
问题描述
我的 URL 重写规则仅适用于 IIS 中的 80 端口.
重写适用于:http://localhost:80 --> http://localhost:8100
重写适用于:http://localhost:80/redirect --> http://localhost:8100
重写不适用于:http://localhost:8080 --> http://localhost:8100
重写不适用于:http://localhost:8080/redirect -->http://localhost:8100
我的 web.config 如下:
<块引用>
web.config 仅适用于默认的 http 端口 80/443,但不适用于特定端口.
必须在 web.config 中进行哪些更改才能使用所有端口?
主要问题是变量{HTTP_HOST}
已经包含了PORT
信息.
要解决此问题,您需要调整两件事:
- 扩展匹配模式
- 为重定向设置正确的地址
我调整了您的 web.config
以查看它应该如何与您的示例配合使用:
My URL Rewrite rule only works for port 80 in IIS .
The rewrite works for : http://localhost:80 --> http://localhost:8100
The rewrite works for : http://localhost:80/redirect --> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080 --> http://localhost:8100
The rewrite doesnt work for : http://localhost:8080/redirect --> http://localhost:8100
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>
The web.config is only working on default http port 80/443 but not for an specific port.
Which changes has to be made in the web.config for working with all ports?
The main problem is the variable {HTTP_HOST}
which already contains the PORT
information.
To solve this issue you need to adjust two things:
- Extend the matching pattern within
- Set the correct address for the redirect
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屋!