1

如何在directadmin界面中将自定义httpd.conf代码添加到域的VirtualHosts?

我需要添加以下行以将 http 重定向到 VirtualHost 端口 80 和 443 中我的域上的 https:

<VirtualHost *:80>
      ServerName www.example.com
      Redirect "/" "https://www.example.com/"
</VirtualHost>

<VirtualHost *:443>
      # Use HTTP Strict Transport Security to force client to use secure connections only
      Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

      # Further Configuration goes here
      [...]
</VirtualHost>

我已经用这个 htaccess 重定向解决了它:

# Redirect if http
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# set header if https
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
4

1 回答 1

1

不知道你为什么要使用 httpd 配置来尝试这个。您需要更新 .htaccess 文件以将所有 HTTP 流量重定向到 HTTPS

尝试使用以下 .htaccess 代码。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L] 
于 2016-05-05T11:05:42.123 回答