0

I have an apache webserver that has about 150 VirtualHosts spread out over 9 IP addresses. I'd like to redirect or rewrite http connections to https. The solutions I've found have the rewrite/redirect inside the definitions but since this server has so many, I was hoping there was a more elegant way of doing it other than adding 150 rewrites.

Its ubuntu 22 btw.

Any ideas?

  • 1
    Does https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever help with your question? – Tero Kilkanen Mar 26 '24 at 07:26

1 Answers1

1

You could use a redirect to https with the %{http_host} variable. Just bind to port 80 and redirect everything to https. No need to know what the hostname is.

Untested but this should work :

<VirtualHost *:80>
  <Location "/">
    Redirect "https://%{HTTP_HOST}%{REQUEST_URI}"
  </Location>
</VirtualHost> 

almost the same question