[英]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如下:
<?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上起作用,而在特定端口上不起作用。
為了使用所有端口,必須在web.config中進行哪些更改?
主要問題是變量{HTTP_HOST}
,該變量已經包含PORT
信息。
要解決此問題,您需要調整兩件事:
我對您的web.config
進行了調整,以查看它如何與您的示例一起使用:
<?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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.