【问题标题】:Not redirecting from http to https automatically using .htaccess不使用 .htaccess 自动从 http 重定向到 https
【发布时间】:2019-11-01 21:46:35
【问题描述】:

试图将我的网站从 http 重定向到 https,但它不起作用...网站同时在 http 和 https 上打开。

这是我目前在我的 htaccess 文件中使用的代码部分,但此代码不会使用 https 自动重定向网站,并使网站同时使用 http 和 https 打开。这太令人困惑了。

    ------------------------------------------------

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule . /index.php [L]

    </IfModule>

    # END WordPress
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-SSL} !on
    RewriteCond %{HTTP_HOST} ^www\.surffares\.com$
    RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
    RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
    RewriteRule ^/?$ "https\:\/\/www\.surffares\.com\/" [R=301,L]

------------------------------------------------------------------------

但是这段代码不起作用...

这是 Godaddy 建议在 htaccess 中用于自动重定向的代码, 但是这段代码只加载首页,自动重定向前面 只有页面,但没有打开其他页面,当我点击任何其他页面时, 它显示了一个未找到的错误。

---------------------------------------------------------------------
    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
    RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

--------------------------------------------------------------------

Godaddy 客户支持告诉您需要在 .htaccess 中提取内页。

如何自动将我的网站从 http 重定向到 https 并拉取网站的所有内页。

注意:我的网站在 php mvc laravel 中

【问题讨论】:

标签: apache http ssl


【解决方案1】:

我已经快速构建了一个配置来测试这个场景。在 Apache VirtualHost 中,您需要确保 htaccess 文件受到 apache 的尊重,AllowOverride

这是 VirtualHost 中的配置:

    <VirtualHost *:80>

     ServerName test.com
     DocumentRoot /var/www

    <Directory "/var/www>
      Require all granted
      AllowOverride all
    </Directory

  </VirtualHost>

然后,在 /var/www/.htaccess 中定义以下内容:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

希望对您有所帮助。

【讨论】:

  • :80> ServerName test.com DocumentRoot /var/www 要求所有授予 AllowOverride all RewriteEngine On RewriteCond %{ HTTPS} off RewriteRule (.) https://%{HTTP_HOST}/$1 [R=301,L] 需要这样写吗?
  • 不,我编辑了我现有的配置,它有效,但现在的问题是,当我输入没有 www 或 https 的简单 url 并尝试打开另一个页面时,例如 xyz.com /abc ...它在主页重定向我...它只发生在两个页面上...联系和付款页面...我不明白原因
  • 在您的配置中搜索重定向。我提供给你的 sn-p 不会导致这些问题。
猜你喜欢
  • 2017-07-18
  • 1970-01-01
  • 2018-09-08
  • 2019-02-12
  • 2015-05-03
  • 2019-04-11
  • 2019-03-18
  • 2012-10-11
相关资源
最近更新 更多