0

I have a web server that runs website example.com. I have configured http to https redirect on apache; See below

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

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

A request on http is redirected successfully Internally.

So the problem is External request they have to go through Squid Reverse Proxy. And when try to connect to http://example .com a http connection is established. Not https, the redirect is unsuccessful.

If we enter the url as http://example.com/index.html, the connection redirects to https successfully.

Does anyone have an idea on how we can sort this issue?

1 Answer 1

0

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.

1
  • Thank you for responding. I did try the suggested solution, and still not working. However after playing around with php, I found that the problem is caused by Squid. Because when I check the protocol for the website via php it show that the connection is https.
    – MarvinD
    Commented Apr 22, 2021 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .