【问题标题】:Ways to redirect http:// to https://将 http:// 重定向到 https:// 的方法
【发布时间】:2019-02-23 11:29:30
【问题描述】:

我们在带有 Apache、PHP 5.6 和 MySQL 5.6 的 Ubuntu 服务器上托管了一个 Drupal 8 应用程序。我想知道我们可以通过多少种方式将域从 http:// 重定向到 https:// 协议。

我尝试了以下方法

  1. 使用重定向从虚拟主机配置文件。
  2. 在项目的 .htaccess 文件中启用了重写规则并提供了重定向条件。

当我使用上述方法时,当请求数量增加时,网站正在下降。如果我删除重定向条件,即使有更多请求到达服务器,站点也可以正常工作。

所以,我想知道有没有其他方法可以将域从 http:// 重定向到 https:// 协议而不会对服务器造成负担。

【问题讨论】:

  • 您使用的是Redirect 还是RedirectMatch 指令?后者启用正则表达式处理,并不总是必要的。您还应该在 htaccess 中禁用默认 https 检查
  • 我正在使用重定向@msg

标签: php apache .htaccess drupal-8 httpd.conf


【解决方案1】:
  • 在您的 httpd.conf 中配置 mod_rewrite 以实现此类重定向

例如:

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
<VirtualHost *:80>
  <IfModule mod_rewrite.c>
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
  </IfModule>
</VirtualHost>

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R]

LoadModule rewrite_module  modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [L,R]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多