Most redirects are working. One of them is not - PLEASE HELP

OK, my primary website is www,groundthumpinmotors,com and I also own www,groundthumpingmotors,com (thumpin and thumping)

I want ALL traffic, no matter whether it is www or non-www, or whether it is http or https, or whether it is either of my two domains, to ALL redirect to

Where did you configure the redirect? As page rule?

1 Like

The following should do the trick

1 Like

I currently have two A records setup on Cloudflare DNS screen:

  1.” pointing to my IP address
  2. “www” pointing to the same IP address

Also in Cloudflare, I also have SSL set to “Full Strict” and also have turned on “Always use HTTPS”.

Next, in my Cpanel redirect section, I have set up so that my htaccess has the following in it now:
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.)$ "" [R=301,L] RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-SSL} !on RewriteCond %{HTTP_HOST} ^groundthumpinmotors\.com [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.
)$ “$1” [R=301,L]

The results of the above are almost perfect except for one issue. Below is what I am getting: -> = CORRECT -> = CORRECT -> = CORRECT (This one does remove www like it should) -> = NOT CORRECT (does NOT remove the www like it should)

I am not understanding why if the user adds the www in front of, the redirect is not removing the www, and instead it is leaving it in place. When doing the same thing to my 2nd domain name, with the (g) in the domain name, it does work properly.

What am I missing here? How do I make this work?

Also, btw, if I am turning things on in Cloudflare that are unnecessary or redundant, please let me know. Also, if I am adding htaccess code that is unnecessary, please let me know.

PS - For testing, I have added a Cloudflare page rule specifically to redirect to and it does work, but why am I having to do this in the first place. It is wasting a page rule of which I only have 2, so rather not waste it on this issue.

Thanks in advance for any help you can provide on this. Take care everyone!

If you prefer to do that server side I’d expect the following to work

RewriteCond %{HTTP_HOST} groundthumpingmotors
RewriteRule (.*)$1 [R=301,L]
1 Like

will that cover both:

What about it? You were asking for redirects to it, so that domain is not involved at all.

Or do you mean the HTTPS/non-www redirects? That can be done with Cloudflare’s Always-use-HTTPS. Non-www is a different story and can be achieved with the following page rule

1 Like

Thank you. Yes, I do know that adding that page rule you mentioned can fix the problem, but my question is trying to understand why my current setup might not be working. I’d prefer not to use 1 of my only 2 available page rules for this task if there is a way to accomplish it local server side / htaccess. I was just wondering if my Cloudflare might be configured incorrectly to cause my htaccess setup to fail on that one specific task. It’s weird that it only fails to redirect specifically when typing www.groundthumpinmotors,com, but it redirects properly when typing www.groundthumpingmotors,com … How can that be. I am using the exact same htaccess rules for both which are:

RewriteCond %{HTTP_HOST} ^$ [OR]

RewriteCond %{HTTP_HOST} ^$

RewriteRule ^(.*)$ “$1” [R=301,L]

RewriteCond %{HTTPS} off

RewriteCond %{HTTP:X-Forwarded-SSL} !on

RewriteCond %{HTTP_HOST} ^$ [OR]

RewriteCond %{HTTP_HOST} ^$

RewriteRule ^(.*)$ “$1” [R=301,L]

Could it have something to do with my DNS settings in Cloudflare? Perhaps the fact that I have both “groundthumpinmotors,com” and “www” both as separate A Record entries both pointing to my domains IP address? Do I need both in there, or should I be using CNAME for anything instead? I am baffled?

Right now, all of these work properly and redirect to as they should:

and these do not redirect properly because they leave the www in there:

.htaccess questions are a bit beyond the scope of this forum as they are not Cloudflare specific but about a general configuration issue.

That being said, you should be able to trim down that rewrite configuration to one rule only. I had something prepared but am right now on a mobile device and cant post it. Shouldnt anybody else post anything in the meantime (or you find the solution), then I will get back to you in a couple of hours.

Also, its not two but three page rules and that per domain.

1 Like

OK thanks. I just wasnt sure if my Cloudflare DNS config was incorrect in some way and causing any kind of problem here? Should I have both “www” as well as “” both added as A Records in there? Or should I be using CNAME instead for www or vice versa? Always been confused by A Record vs CNAME.

FYI, I removed the www A Record and replaced it with a CANME www instead, but it did not change anything sadly. I will put it back to A Record instead and try and figure out something else :frowning:

I have another secondary question unrelated. If I am using the free SSL you guys provide and have SSL set to Full trict and force https always, do I still need to use Opportunistic Encryption as well, or is that going to conflict? Should I have both on?

I don’t use Opportunistic Encryption because of the reasons you stated. So I leave it turned off.

I also have HSTS preload enabled. No decent browser should even initiate an HTTP connection to my site.

1 Like

Thank you for that info. I was considering enabling HSTS as well, but when I clicked on the HELP info button, the warnings kinda scared me away from it. Seems complicated and possible to have issues with no access to website if I make the wrong change somewhere. Scary for a newbie :slight_smile:

I’m a bit late to this thread, but I don’t see what the Page Rule issue is on the G site. That site doesn’t need the Always Use HTTPS or the Auto HTTPS Rewrites. The one page rule @sandro posted early on should send everybody to the proper site.

On the non-G site, a short rewrite should eliminate the www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

In DNS, I use “A” records and make sure my host is properly configured for www and non-www. In your case, the naked domain should be an A record, and the www should be as well, since your server needs to respond to www.

1 Like

Give that HSTS some thought for a while. Once you get HTTPS running smoothly, give HSTS a second look. The preload system also requires that all subdomains are HTTPS as well.

1 Like

Thank you for your responses. I have decided to not mess with it on my server side for now and let it all be handled by Cloudflare. I hope this isn’t a bad idea in the end. Just worries me a bit if I disable Cloudflare for some reason temporarily, that my users will not get redirected properly. Regardless, I implemented both of the rules posted above by Sandro to cover both of my domain redirection needs. Seems to be doing it’s job with that set up. Thank you for that! I will look into the HSTS stuff eventually when I get brave :slight_smile:

PS - Would it be a bad idea to have redirect rules both on Cloudflare as well as on my local server? Does it create double redirects or anything like that (I dont know the terminology). Basically, does it slow down the end users access to the website in any way at all. Idea being that if I turned off Cloudflare, then my htaccess would take over and still redirect properly. Also, if I have both enabled, which takes precedence?

Redundancy wouldn’t be a bad idea. The redirects will be ignored on your server as long as Cloudflare (which takes precedence) is doing it for you.

1 Like

OK, good to know…thank you for your help with this!

I understood you use the same configuration for both domains on your server. In that case the following directives should cover all scenarios

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} www|groundthumpingmotors [NC]
RewriteRule (.*)$1 [R=301,L]

Just make sure your SSL mode is at least “Full” (but it shouldnt be anything else anyhow) otherwise you’ll run into the usual “too many redirects” issue, which every second thread seems to be about :smile: