1

How add custom httpd.conf code to the VirtualHosts of a domain in the directadmin interface?

I need to add this lines to redirect http to https on my domains in the VirtualHost Port 80 and 443:

<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>

I've solve it with this htaccess redirect:

# 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
Overnet
  • 965
  • 3
  • 12
  • 20

1 Answers1

1

Not sure why are you trying this with httpd configuration. You need to update .htaccess file to redirect your all HTTP traffic to HTTPS

Try with following .htaccess code.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L] 
24x7servermanagement
  • 2,520
  • 1
  • 13
  • 11