Simple IIS URL Rewrite

Deadly 提交于 2020-01-03 18:54:50

问题


Simple question. I need to redirect all http 80 and https 443 requests on a specific subdomain URL to an alternative SSL port https 444.

Example: http://sub.corp.com --> https://sub.corp.com:444 Example: https://sub.corp.com --> https://sub.corp.com:444

I only wish to use IIS 7.5 URL Rewrite module.

Thanks.


回答1:


The following URL rewrite rule should do what you want:

<rewrite>
    <rules>
        <rule name="Redirect to port 444" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTPS}" pattern="^ON$" negate="true" />
                <add input="{SERVER_PORT}" pattern="^444$" negate="true" />
            </conditions>
            <action type="Redirect" url="https://sub.corp.com:444/{R:0}" />
        </rule>
    </rules>
</rewrite>

It redirects to https://sub.corp.com:444 whenever HTTPS is not ON or when the port number is not 444. The site should have bindings to port 80 (with HTTP), 443 (with HTTPS for standards SSL) en 444 (with HTTPS) for this to work.




回答2:


Marco's solutions works fine, in case somebody is wondering how to apply this in IIS. you add this to the web.config file. If you create a Virtual Directory in IIS the selected physical folder will have a web.config created.

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Redirect to port 50443" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTPS}" pattern="^ON$" negate="true" />
                    <add input="{SERVER_PORT}" pattern="^50443$" negate="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}:50443/{R:0}" />
            </rule>
        </rules>
    </rewrite>
 </system.webServer>
</configuration>


来源:https://stackoverflow.com/questions/7855469/simple-iis-url-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!