首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从我的域的任何HTTP url重定向HTTPS

问从我的域的任何HTTP url重定向HTTPS
EN

Stack Overflow用户
提问于 2015-03-31 22:20:28
回答 1查看 329关注 0票数 0

我有一个IIS服务器,用于通过TeamCity运行的CI。我非常希望我的域名上的任何网址被重定向到该网址的HTTPS版本。

我已经阅读了这里链接的教程:http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

代码语言:javascript
复制
    <system.webServer>
        <rewrite>
            <rules>
            <clear />           


    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" negate="true" />
        <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
    </rule>

    <rule name="Subdirectory HTTP to HTTPS redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
            <match url="(^admin/.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
    </rule> 

        </rules>           
    </rewrite>
</system.webServer>

此外,这是我的web.config的当前版本,遵循本教程:

我真的不确定我做错了什么,因为我的域名的主urls似乎重定向到https,但许多子域只有404,除非你显式指定HTTPS。任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2015-03-31 22:44:40

请看下面的例子,包括截图(链接)。不安全的默认文档也应该是index.htm。

代码语言:javascript
复制
<!DOCTYPE html><html>
<!-- This is index.htm -->
<head><script>
if (window.location.protocol != "https:") {
    window.location.protocol = "https:";
    window.location.reload();
}</head></html>

ASP重定向解决方案:

<% Response.Redirect "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") %>

PHP重定向解决方案:

<?php header('HTTP/1.1 302 Found'); header('Location: https://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]); ?>

IIS站点中的处理程序配置:Handler config

不安全站点中的错误页面:Custom error pages

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29370878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档