Another non-www to www problem I can't seem to fix

Keywords: WordPress Multisite - AWS - Technical issue - Domain Name (DNS)

bnsupport ID: 66101577-0239-ef82-babf-e5ae13582450

bndiagnostic output:

? Apache: Found possible issues
? Resources: Found possible issues
https://docs.bitnami.com/general/apps/wordpress/administration/use-pagespeed/#disable-pagespeed
https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-errors-apache/
https://docs.bitnami.com/installer/faq/linux-faq/administration/increase-memory-linux/

bndiagnostic failure reason: The suggested guides are not related with my issue

Description:
I realise there is a ton of posts about this but I’ve honestly read for hours trying things and I’m just stuck.

Wordpress Multisite with three sites on different domains running.

I need the all non-www versions of the all sites (primary and others) to redirect to the www versions, http and https.

At the moment this is what happens when you type in a browser:

I’ve tried adding in various similar lines to this in various places in wordpress.conf, httpd-vhosts.conf, htaccess.conf, etc

RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$
http://www.%{HTTP_HOST}/$1 [R=301,L]

But some of these files seem unused, and nothing seems to make any difference! I’m afraid I’m just shooting in the dark here!

Any pointers?

Hi @Ralpharama,

Thanks for using Bitnami. I checked your bndiagnostic information but I can’t find the non-www to www redirection in any config file. Can you tell us where did you configure it?

I also visited your website using curl to check the redirections and it worked fine, from HTTP to HTTPS. I also visited your website using the browser without errors

$ curl -LI "http://te***ls2.eng***ati.com"
HTTP/1.1 302 Found
Date: Tue, 16 Nov 2021 18:15:44 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Location: https://te***ls2.eng***ati.com/
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Tue, 16 Nov 2021 18:15:44 GMT
Server: Apache
X-Powered-By: PHP/7.3.18
Link: <https://te***ls2.eng***ati.com/wp-json/>; rel="https://api.w.org/", <https://te***ls2.eng***ati.com/wp-json/wp/v2/pages/2>; rel="alternate"; type="application/json", <https://te***ls2.eng***ati.com/>; rel=shortlink
Set-Cookie: ADFLoggedOut=mpzNNuqERUqctdOfrVaFPLXFdm5aA6qqsKM32s2N9O9rlY7pii; expires=Thu, 16-Dec-2021 18:15:44 GMT; Max-Age=2592000; path=/; domain=eng***ati.com
X-Frame-Options: SAMEORIGIN
Cache-Control: max-age=0, no-cache
Content-Type: text/html; charset=UTF-8

Can you tell us for which subdomain are you having issues? Also notice that according to the bndiagnostic information, you generated a SSL certificate for the te***ls2.eng***ati.com domain only, and subdomains won’t be secured with that certificate.

Hi Gongomgra,

Thanks for looking into this!

I removed the non-www to www lines as I wasn’t sure which file to put them in! There were a few suggestions and for example bitnami.conf etc. Can you advise which file and where I should put these lines?

The diagnostics are for our staging server, as I can’t test on the live server. Staging uses
te***ls2.eng***ati.com as the primary site instead of www.

So yes the tests are routing through our live site as that’s where the DNS is pointing for non-www. I’m not sure how to do this without testing on live.

If you try https://eng***ati.com/, or http://eng***ati.com/ you’ll see they both redirect to the https://eng***ati.com/wp-signup.php?new=des***ion.biz

Also try https://des***ion.biz/, or http://des***ion.biz/ you’ll see they both redirect to the https://www.eng***ati.com/wp-signup.php?new=eng***ati.com

Maybe we could test a dummy subdomain to stand in for ‘non-www’ on the staging server - I could add DNS to point there, if that would help?

The staging and live sites are identical except for the final domains used and the DB strings, I can also do a bnconfig on the live site if that helps?

Thanks for help and apologies for the confusion!.

I ran the bndiagnostic-tool on the live server, so this shows the actual non-www to www redirect, so it is less confusing. As I say, I’m extremely reluctant to experiment with the live server though!

If we can work out a way to test this in theory on the staging then great, but as a last case I’ll try out-of-hours on live if you can suggest which lines to put in which file? :slight_smile:

Thanks again!

Here is the live server diagnostic code: b31fa89c-681d-5966-ab07-e5ccd4fb6776

Hi @Ralpharama,

Thanks for your message. To avoid mixing topics with the different servers, and to avoid issues with the production server, I agree to focus on the staging one.

However, for this server I would need to have more information about the second domain you are testing, so I can check it on my side. Can you share the full name?

So yes the tests are routing through our live site as that’s where the DNS is pointing for non-www. I’m not sure how to do this without testing on live.

I’m afraid I’m not fully understanding this message. Can you clarify a bit? Is te***ls2.eng***ati.com a CNAME of eng***ati.com or just a totally different domain (A Record)?

As you are using an staging server, I think it would be easier to start from scratch. Can you launch a new WordPress Multisite server and configure the main blog and a second site using our guide below? Do you plan to use different domains or sub-domains only?

https://docs.bitnami.com/aws/apps/wordpress-multisite/configuration/configure-wordpress-multisite/

Just configure both sites so you can access using the full domain name for the moment, without configuring any redirection in Apache yet. Let’s see if you get any issue with this step first.

Regards,
Gonzalo

Hi Gonzalo,

I’m afraid a new version would be different to the current live sites and config?

Sorry for the confusion.

Before I do what you ask, can you tell me where the redirect should in my my current configuration/version, I honestly think just need to know what file to alter.

Imagine the question was, “How do I redirect xxx.domain.com to www.domain.com?” - i.e. which file to I alter in my staging setup to do that? Then I can alter that to do non-www to www the same way :slight_smile:

Thanks!

Hi Gonzalo,

This is now fixed, I added these lines to .htaccess in wordpress/htdocs and it now works fine with http:// and https:// non-www, both redirecting to the correct https://www sites.

RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Thanks for your time. I was testing on the wrong box due to DNS, which was the main problem, but it is confusing where exactly these lines should go according to documentation!

Hi @Ralpharama,

Thanks for your message. Find my comments in-line

I’m afraid a new version would be different to the current live sites and config?

You are right, newer versions use a different structure, but the documentation still has the information for the previous versions (approach B). You can get more information about these changes in the link below

https://docs.bitnami.com/aws/faq/get-started/understand-upcoming-changes/

Before I do what you ask, can you tell me where the redirect should in my my current configuration/version, I honestly think just need to know what file to alter.

If you are using an old image with approach B, you can add the redirect config to the /opt/bitnami/bitnami.conf file. According to your latest bndiagnostic bundle, you have there a redirection configured for HTTP to HTTPS, but nothing for non-www to www domains.

https://docs.bitnami.com/aws/apps/wordpress-multisite/administration/force-https-apache/

This is now fixed, I added these lines to .htaccess in wordpress/htdocs and it now works fine with http:// and https:// non-www, both redirecting to the correct https://www sites.

I see you updated the /opt/bitnami/apps/wordpress/conf/httpd-app.conf file to set AllowOverride All. Take into account using .htaccess files is not recommended by the Apache Software Foundation for security and performance reasons. Your installation has an htaccess.conf file where you can add the needed configuration. You can get more information about this setup in the next guide

https://docs.bitnami.com/aws/infrastructure/lamp/administration/use-htaccess/

Apart from the above, I’m glad you managed to fix your issue! :slight_smile: Let us know if we can close this thread as solved or if you have any other questions

Thanks Gonzalo,

Not intentionally! What is the effect of this setting?

Okay, great, I’ll take a look at switching it to this file.

Thanks for taking the time to get back to me with this extra information.

Hi @Ralpharama,

You can get more information about the AllowOverride directive in the official Apache documentation linked below

https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.