Hi all,

 

I’ve been banging my head against this issue for a couple of weeks and I’m hoping someone here can provide some guidance or sugestions.

 

Some Background

 

I run several WordPress sites on my Bitfolk VPS, and I have AWS CloudFront in front of them. Because CloudFront serves the www.domain.name URLs, I have origin-www.domain.name DNS entries pointing to my VPS, and Apache VirtualHosts configured that respond to multiple ServerNames and ServerAliases:

 

On the VPS I am serving the websites over HTTP and HTTPS (using Let’s Encrypt for certificates), but CloudFront is configured to redirect HTTP requests to HTTPS (using AWS Certificate Manager certificates), and to only communicate with the origin over HTTPS. The Apache VirtualHosts are configured to redirect any domain name to https://www.domain.name, which is the URL that each WordPress site is configured to use (for the WordPress Address and the Site Address).

 

Now to the problem

 

I see different behaviours with the redirects on different websites. For example, if I test all the URI combinations for one of my sites using a site like https://httpstatus.io/, I get:

  1. http://wofeckcsclub.co.uk --> https://wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  2. http://origin-www.wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  3. http://www.wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  4. http://www-test.wofeckcsclub.co.uk --> https://www-test.wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  5. https://wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  6. https://origin-www.wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads
  7. https://www.wofeckcsclub.co.uk --> website loads
  8. https://www-test.wofeckcsclub.co.uk --> https://www.wofeckcsclub.co.uk --> website loads

 

On the whole, this is fine. I’d rather 1) and 4) had a single redirect to https://www.wofeckcsclub.co.uk but I think this is a result of CloudFront first redirecting to HTTPS and then the HTTPS site redirecting to the correct URI, so not sure I can do much about this (except maybe enable CloudFront to communicate with the origin via HTTP, and allow the HTTP origin site to redirect to the correct URI).

 

However, a few of my websites do this instead:

  1. http://savouredescapes.com --> https://savouredescapes.com --> https://www.savouredescapes.com --> website loads
  2. http://origin-www.savouredescapes.com  --> https://www.savouredescapes.com --> website loads
  3. http://www.savouredescapes.com --> https://www.savouredescapes.com --> website loads
  4. http://www-test.savouredescapes.com --> https://www.savouredescapes.com --> website loads
  5. https://savouredescapes.com --> https://www.savouredescapes.com --> website loads
  6. https://origin-www.savouredescapes.com --> website loads [not correct]
  7. https://www.savouredescapes.com --> website loads
  8. https://www-test.savouredescapes.com --> website loads [not correct]

 

For these websites, URIs 6) and 8) are not being redirected, and display the website with the original URI in the browser. All the VirtualHosts are configured the same, and look like this:

 

<VirtualHost *:80>

        DocumentRoot /var/www/savouredescapes

        ServerName www.savouredescapes.com

        ServerAlias savouredescapes.com origin-www.savouredescapes.com www-test.savouredescapes.com

        <Directory /var/www/savouredescapes/>

                AllowOverride All

        </Directory>

        ErrorDocument 403 /error/noindex.html

        ErrorLog ${APACHE_LOG_DIR}/savouredescapes-error.log

        CustomLog ${APACHE_LOG_DIR}/savouredescapes-access.log combined

RewriteEngine on

RewriteCond %{SERVER_NAME} =savouredescapes.com [OR]

RewriteCond %{SERVER_NAME} =origin-www.savouredescapes.com [OR]

RewriteCond %{SERVER_NAME} =www.savouredescapes.com [OR]

RewriteCond %{SERVER_NAME} =www-test.savouredescapes.com

RewriteRule ^ https://www.savouredescapes.com%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

 

As far as I can tell, a URI like https://origin-www.savouredescapes.com should be hitting my VPS direct (no CloudFront, DNS points to my VPS) and getting redirected to https://www.savouredescapes.com, which should then be served via CloudFront. However, Apache doesn’t seem to be performing this redirect. In the Apache logs, I see entries like this in the ‘access’ log:

 

188.166.109.207 - - [09/Jul/2022:11:19:04 +0100] "GET / HTTP/1.1" 200 58957 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0"

 

As opposed to something like this when the redirect does work:

 

188.166.109.207 - - [09/Jul/2022:11:11:18 +0100] "GET / HTTP/1.1" 301 568 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0"

 

And nothing in the error logs. So I’m not sure how to troubleshoot further why the redirects aren’t working as expected for this particular website.

 

In addition, because this does work on some of my other sites (like the https://www.wofeckcsclub.co.uk site I first showed the results for), I presume WordPress (or something else?!?) must be doing an internal redirect, rather than Apache? Again, as far as I can tell the WordPress configurations are the same; there are no obvious plugins that would configure 301/302 redirects on the WordPress instances that do work, although that’s not to say such a plugin hasn’t been installed and configured in the past and since removed, leaving the configuration running on the WordPress site…?

 

I’m wondering if anyone on this list has any relevant WordPress experience, and any suggestions for files/configurations to check in WordPress to see where these redirects might be happening? Also more than happy to explore the fact that my Apache configuration could be wrong and need tuning, and open to any other suggestions to try and ‘fix’ these redirects one way or another (the main thing I want is consistency across all of them!).

 

Many thanks in advance,

 

Paul