Apache2 RewriteCon

Apache2 RewriteCon

我们正在使用 Apache2,并且我强制所有 http 连接转到 https。我已更新 conf 文件,如下所示:

# Call coming in has been redirected by AWS and is not secure, to fix, open the login.jsp file:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

然而,这会导致问题,现在请求只是指向 login.jsp,而不是所有 http 到 https。

任何帮助将不胜感激

答案1

你应该为你的网站创建一个 VirtualHosts,如下所示

<VirtualHost *:80>
  ServerName  yourwebsite.com
  ServerAlias www.yourwebsite.com
  Redirect permanent / https://yourwebsite.com/ 
</VirtualHost>

将上述代码放入 conf 文件中,然后重新启动 apache2

希望有帮助!

相关内容