php - SSL 重定向 .htaccess 不工作

标签 php .htaccess ssl

在托管中安装了 SSL。安装后,它尝试更改 .htaccess 中的重定向以获得带有 greenpad 锁定符号的 https://但不起作用我尝试的只是在 htaccess 文件中强制 https 它不起作用。下面是我的脚本中已经存在的 .htaccess 代码。因为我添加了 RewriteRule ^(.*)$ https:// 它没有工作。

<IfModule mod_rewrite.c>
        RewriteEngine On
        Options -Indexes
        #RewriteBase /vrs7
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)/l([0-9]+)$ http://%{HTTP_HOST}/$1/l.$2 [R=301,L] 
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)/n([0-9]+)$ http://%{HTTP_HOST}/$1/n.$2 [R=301,L] 
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)/p([0-9]+)$ http://%{HTTP_HOST}/$1/p.$2 [R=301,L] 
#Adds trailing slash
        #RewriteCond %{REQUEST_FILENAME} !-f
        #RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
        #RewriteRule ^(.*)$ $1/ [R=301,L]
        #Remove trailing slash
        #RewriteRule ^(.*)/$ $1 [R=301,L]
        RewriteCond %{QUERY_STRING} ^(.*)?gclid=(.*) [OR]
        RewriteCond %{QUERY_STRING} ^(.*)?utm_source=(.*) [OR]
        RewriteCond %{QUERY_STRING} ^(.*)?fb_action_ids=(.*)
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)$ index.php?/$1 [L]
        # Enforce www
        RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
        RewriteRule ^(.*)$ index.php?/$1 [PT,QSA]
        ErrorDocument 404 /404.shtml
    </IfModule>

我正在为一个自定义的 php 网站尝试这个。这是假期租赁脚本,里面没有在管理面板中添加 https://的选项。所以我试图在 htaccess 文件的帮助下实现它。

最佳答案

将站点从 http 重定向到 https:

RewriteEngine on
RewriteCond %{SERVER_NAME} =INSERTYOURSERVERNAMEHERE
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

INSERTYOURSERVERNAMEHERE 替换为...您的服务器名称,不带协议(protocol),即

RewriteCond %{SERVER_NAME} =example.com

关于php - SSL 重定向 .htaccess 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49379763/

相关文章:

php - 在 php 7 (ubuntu14.04) 中安装 cURL

php - 我们如何才能看到特定视频观看了多少次? (在PHP中)

javascript - 如何将 jQuery 自动完成(=实时搜索)与 Laravel Controller 结合使用

regex - 用/使用 .htaccess 替换 URL 中的 .php

ssl - 在自定义客户端上使用 session 票证 (RFC 5077)

php - 如何使用 PHP 读取串口

apache - 重写规则案例 "Internal server error"(里面的 error.log)

linux - 如何在 .htaccess 中阻止未知浏览器?

java - java如何选择最强的密码在jsse中使用?

c# - 当我尝试使用 visual c# 连接 SQL Server 时收到此错误消息