【问题标题】:Auto redirect http site url to https in cpanel在 cpanel 中自动将 http 站点 url 重定向到 https
【发布时间】:2012-04-22 00:01:15
【问题描述】:

将站点 url http 重定向到 https..为此我在我的 cpanl public_html 根目录中上传 .htaccess 文件。文件的代码为

RewriteEngine On  
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://sitename.in/$1 [R,L]

在我托管此文件后,它也没有将我的网站重定向到 https 协议

【问题讨论】:

    标签: http ssl https ssl-certificate cpanel


    【解决方案1】:

    我在网站的索引页面中添加了以下几行代码

    if($_SERVER["HTTPS"] != "on")
    {
    header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    exit();
    }
    

    然后网站url重定向到https链接

    【讨论】:

      【解决方案2】:

      我刚刚修改了答案第一部分中的 .htaccess 文件,以便我的 Wordpress 网站将 http:// 重定向到 https://。我不需要修改索引页面,没有它对我来说效果很好。感谢作者,因为它完成了我对安全证书迁移的追求。

      我的完整文件 .htaccess 文件对我来说看起来像这样。我建议制作一个本地副本,因为在我在这里找到适合我的正确答案之前,我破坏了我的网站几次:

      #RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
      #RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
      
      # BEGIN WordPress
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>
      
      # END WordPress
      
      Options +FollowSymlinks
      
      RewriteCond %{SERVER_PORT} 80
      RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
      

      【讨论】:

        【解决方案3】:

        我写这个答案太晚了,但目前它工作正常。所以试着在你的根目录 .htaccess 文件上做。

        # Force SSL
        <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTPS} !=on [NC]
        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
        </IfModule>
        

        注意:只有在cpanel服务器上安装了mod_rewrite才有效,否则使用基于php的SSL重定向。

        【讨论】:

        • 在使用 cPanel 安装 Wordpress 的 .htaccess 时非常适合我。谢谢!
        猜你喜欢
        • 2016-04-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        • 2017-03-17
        • 2016-04-05
        • 2021-05-11
        • 2015-11-02
        相关资源
        最近更新 更多