【问题标题】:HTTP to HTTPS Redirection IssueHTTP 到 HTTPS 重定向问题
【发布时间】:2015-09-08 20:04:16
【问题描述】:

我想将 http 请求重定向到 https 节点。

我试过了,

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

请看下面几个测试结果,我执行了,

http://sample.mydomane.co/ 重定向到 https://sample.mydomane.co/

//按预期工作

http://sample.mydomane.co/api-docs/ 未重定向到 https://sample.mydomane.co/api-docs/

//没有按预期工作

编辑:这是我的.htaccess 文件

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    #Options +FollowSymLinks
    RewriteEngine On

    RewriteRule ^(api-docs|docs)($|/) - [L] # HERE IS THE PROBLEM I THINK

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # redirect all http -> https
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</IfModule>

请告诉我如何实现或解决此问题。

【问题讨论】:

  • 我编辑了问题以包含 .htaccess 文件。请注意评论“这是我认为的问题”。

标签: php apache https


【解决方案1】:

我成功使用了以下规则,注意正则表达式模式的区别

RewriteRule ^(.*)$ https://domainname/$1 [R,L]

【讨论】:

【解决方案2】:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

阿帕奇维基

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多