Skip to main content
Minor Code Updates
Source Link
Anaksunaman
  • 17.5k
  • 4
  • 44
  • 52

When trying to connect to http://example.com, an HTTP connection is established, not HTTPS and the redirect is unsuccessful.

One issue that you seem to have is that there are no entries for http://example.com in your Apache virtual host configuration. The www prefix is technically a subdomain of example.com and is therefore considered a separate site for resolution. Excluding any issues with Squid, a simple fix would be to modify your virtual hosts to account for the different variations of example.com with the ServerAlias directive:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Serve https://example.com and https://www.example.com
# from the same DocumentRoot

<VirtualHost *:443> 
  ServerName example.com 
  ServerAlias www.example.com
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

Note that you could also redirect https://example.com to https://www.example.com:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Redirect https://example.com to https://www.example.com

<VirtualHost *:443> 
  ServerName example.com 
  Redirect permanent / https://www.example.com
  SSLEngine On #etc... 
</VirtualHost>

# Serve https://www.example.com

<VirtualHost *:443> 
  ServerName www.example.com 
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

You can read more about name-based virtual hosts here.

When trying to connect to http://example.com, an HTTP connection is established, not HTTPS and the redirect is unsuccessful.

One issue that you seem to have is that there are no entries for http://example.com in your Apache virtual host configuration. The www prefix is technically a subdomain of example.com and is therefore considered a separate site for resolution. Excluding any issues with Squid, a simple fix would be to modify your virtual hosts to account for the different variations of example.com with the ServerAlias directive:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Serve https://example.com and https://www.example.com
# from the same DocumentRoot

<VirtualHost *:443> 
  ServerName example.com 
  ServerAlias www.example.com
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

You can read more about name-based virtual hosts here.

When trying to connect to http://example.com, an HTTP connection is established, not HTTPS and the redirect is unsuccessful.

One issue that you seem to have is that there are no entries for http://example.com in your Apache virtual host configuration. The www prefix is technically a subdomain of example.com and is therefore considered a separate site for resolution. Excluding any issues with Squid, a simple fix would be to modify your virtual hosts to account for the different variations of example.com with the ServerAlias directive:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Serve https://example.com and https://www.example.com
# from the same DocumentRoot

<VirtualHost *:443> 
  ServerName example.com 
  ServerAlias www.example.com
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

Note that you could also redirect https://example.com to https://www.example.com:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Redirect https://example.com to https://www.example.com

<VirtualHost *:443> 
  ServerName example.com 
  Redirect permanent / https://www.example.com
  SSLEngine On #etc... 
</VirtualHost>

# Serve https://www.example.com

<VirtualHost *:443> 
  ServerName www.example.com 
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

You can read more about name-based virtual hosts here.

Source Link
Anaksunaman
  • 17.5k
  • 4
  • 44
  • 52

When trying to connect to http://example.com, an HTTP connection is established, not HTTPS and the redirect is unsuccessful.

One issue that you seem to have is that there are no entries for http://example.com in your Apache virtual host configuration. The www prefix is technically a subdomain of example.com and is therefore considered a separate site for resolution. Excluding any issues with Squid, a simple fix would be to modify your virtual hosts to account for the different variations of example.com with the ServerAlias directive:

# Redirect http://example.com and http://www.example.com
# to https://www.example.com

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

# Serve https://example.com and https://www.example.com
# from the same DocumentRoot

<VirtualHost *:443> 
  ServerName example.com 
  ServerAlias www.example.com
  DocumentRoot /usr/www/htdocs 
  SSLEngine On #etc... 
</VirtualHost>

You can read more about name-based virtual hosts here.