How can I enable force HTTPS for Apache webserver for all domains?

Started by licode, December 13, 2022, 11:50:50 AM

Previous topic - Next topic

licode

I tried searching and looking around and found nothing for Apache.
How can I resolve this without htaccess files.


licode



overseer

It's possible to do a permanent redirect in the vhost config:
<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  Redirect permanent / https://example.com/
</VirtualHost>


But a 301 redirect is preferred. In vhost conf or in .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]