【问题标题】:How to force redirect http https on the entire domain如何在整个域上强制重定向 http https
【发布时间】:2017-09-04 14:19:46
【问题描述】:

我最近向我的网站添加了 SSL 证书,并希望将所有页面重定向到其安全“版本”。

目前我的 htaccess 中有以下行:

RewriteEngine On
RewriteBase    /
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]

但是当我手动删除https://www。从 url 中,它只显示常规的不受保护的页面。

无论www如何,如何强制所有页面使用https。

【问题讨论】:

    标签: .htaccess ssl


    【解决方案1】:

    我在我的 FTP 服务器上的主目录 (ex. https://www.example.com/.htaccess) 中使用此代码:

    RewriteEngine On
    RewriteCond %{SERVER_PORT}   !^443$
    RewriteRule  (.*)  https://%{HTTP_HOST}/$1   [L]
    

    希望它对你有用。

    【讨论】:

    • 谢谢,这行得通。不知道为什么我的没有。我会在 6 分钟内接受。
    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 2018-11-07
    • 2020-07-23
    • 1970-01-01
    相关资源
    最近更新 更多