如何将 IIS 服务器中的特定端口重定向到其他端口 [英] How do I redirect a specific port in the IIS server to an other port

查看:68
本文介绍了如何将 IIS 服务器中的特定端口重定向到其他端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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信息.

要解决此问题,您需要调整两件事:

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

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

  1. Extend the matching pattern within
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆