【问题标题】:SSL redirect .htaccess not workingSSL 重定向 .htaccess 不起作用
【发布时间】:2018-08-29 00:06:39
【问题描述】:

在主机中安装了 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 文件的帮助下实现它。

【问题讨论】:

    标签: php .htaccess ssl


    【解决方案1】:
    1. 您是否启用了 default-ssl
    a2ensite default-ssl #this must be enable otherwise  will show
    
    
    1. 您是否在 .htaccess 文件中允许覆盖?
    AllowOverride All
    
    

    【讨论】:

      【解决方案2】:

      将站点从http 重定向到https

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

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

      RewriteCond %{SERVER_NAME} =example.com
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-29
        • 2015-03-07
        • 2015-08-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多