关于iis web.config 域名跳转问题

dengkeyu 2017-09-07 01:10:25
win2008 r2 系统 iis 7.0

要求:

http://xxx.com
http://www.xxx.com
https://xxx.com

全部跳转到 https://www.xxx.com

web.config 怎么修改?
...全文
1867 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengkeyu 2017-09-09
  • 打赏
  • 举报
回复
终于解决了!非常感谢您啊,特别是你的热心和回复及时!
X-i-n 2017-09-08
  • 打赏
  • 举报
回复
一个站点也一样处理啊,http的判断条件改为无https,再把规则合并到一个站点上,然后匹配模式从“全部匹配”切到“任意匹配”就行。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="self" stopProcessing="true">
                    <match url="(.*)" negate="false" />
                    <action type="Redirect" url="https://www.xxx.com/{R:0}" logRewrittenUrl="true" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^xxx.com" />
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
dengkeyu 2017-09-08
  • 打赏
  • 举报
回复
你这个太麻烦了,我以前写过的,就绑定一个站点,就能实现的,可惜我忘记当时 web.config 是怎么写的了...
dengkeyu 2017-09-08
  • 打赏
  • 举报
回复
按照你的要求,测试,所有跳转都失效了...
X-i-n 2017-09-08
  • 打赏
  • 举报
回复
之前是我理解得有问题,URL匹配不包含域名部分,而是https://xxx.com/abc/abc.html?t=1 中的标红部分。 所以只要用(.*)来匹配整个URL(匹配变量是 {R:0}),加到新的HOST后面。最终效果是:将URL中的HOST部分 http(s)://xxx.com 替换成新域名,别的部分不变。 完整的站点设置方法是添加两个站点,一个绑http,一个绑https,各自用一条重定向规则,两个站点的匹配规则不一样,重定向行为一样。 ·http站点绑定域名http://xxx.com和http://www.xxx.com,规则是:匹配所有URL,重定向到https://www.xxx.com。 ·https站点的规则是:匹配HOST是https://xxx.com的访问(匹配条件,HTTP_HOST以xxx.com开头,xxx.com匹配命中,www.xxx.com匹配不命中),重定向到https://www.xxx.com。 HTTP的

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="redirect80" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Redirect" url="https://www.xxx.com:9443/{R:0}" redirectType="Permanent" />
                    <conditions>
                        <add input="{URL}" pattern="(.*)" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

HTTPS的
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="redirect443" stopProcessing="true">
                    <match url="(.*)" negate="false" />
                    <action type="Redirect" url="https://www.xxx.com:9443/{R:0}" logRewrittenUrl="true" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^xxx.com" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
X-i-n 2017-09-07
  • 打赏
  • 举报
回复
直接用这个试试,匹配所有URL,将url里xxx.com后面的部分(比如 https://xxx.com/a.html中的 /a.html)保留,前面的部分无脑替换成 https://www.xxx.com
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rewrite">
                    <match url="^(.*)" />
                    <conditions>
                        <add input="{URL}" pattern="^(.*xxx.com)(.*)" />
                    </conditions>
                    <action type="Rewrite" url="https://www.xxx.com/{C:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
dengkeyu 2017-09-07
  • 打赏
  • 举报
回复
<rule name="WWW Redirect" stopProcessing="true"> <match url="^(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="https://www.xxx.com/{R:0}" redirectType="Permanent" /> </rule> 这个实现了 http://xxx.com http://www.xxx.com 跳转到 https://www.xxx.com 但是没有实现 https://xxx.com 跳转到 https://www.xxx.com 怎么解决?
dengkeyu 2017-09-07
  • 打赏
  • 举报
回复
不行,麻烦你按照我的要求写个web.config 给我
X-i-n 2017-09-07
  • 打赏
  • 举报
回复
http://blog.csdn.net/u013378306/article/details/51064508 IIS管理器配置和web.config配置两种方法都有

6,871

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧