【问题标题】:How do I redirect a specific port in the IIS server to an other port如何将 IIS 服务器中的特定端口重定向到其他端口
【发布时间】:2019-02-02 02:03:33
【问题描述】:

我的 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 中进行哪些更改才能使用所有端口?

【问题讨论】:

    标签: redirect iis web url-rewriting port


    【解决方案1】:

    主要问题是变量{HTTP_HOST}已经包含PORT信息。

    要解决这个问题,你需要调整两件事:

    1. 在范围内扩展匹配模式
    2. 为重定向设置正确的地址

    我调整了您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-06
      • 2021-04-09
      • 1970-01-01
      • 2016-06-15
      • 2014-04-27
      • 2018-06-02
      • 2017-10-07
      • 1970-01-01
      相关资源
      最近更新 更多