redirect - 如何将 IIS 服务器中的特定端口重定向到其他端口

标签 redirect iis web url-rewriting 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>

The web.config is only working on default http port 80/443 but not for an specific port.

必须在 web.config 中进行哪些更改才能使用所有端口?

最佳答案

主要问题是变量{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>

关于redirect - 如何将 IIS 服务器中的特定端口重定向到其他端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52040903/

相关文章:

.htaccess - 拒绝时重定向 |访问

JSF:重定向到url,而不是GET

ios - 如何以编程方式填写网络表单以获取过去的身份验证页面? (在 iOS 中)

c# - 如何在 Javascript 中确定运行时的页面 URL?

node.js - Nodejs重定向url编码

apache - 使用/到 HTTPS 重定向插件域

c# - 需要帮助识别 IIS 中的细微错误……? session ?别处..?

IIS 7.5 静态内容压缩(不一致)

javascript - jqGrid - 在 IE 中产生 SCRIPT5007 错误,但在本地主机上工作

jquery - 一次加载所有内容(图像)以提高网站性能