Redirecting www to non www


#1

Cloudflare with Flexible SSL

Before integrating cloudflare, my website was redirecting from www to non www version. Now it’s showing DNS error. I have added only A record to cloudflare DNS.

I have created a page rule - Forwarding URL - www.mydomain.com/* to https://mydomain.com

Still it’s not working.


#2

Hey again :smile:

I just tested your scenario. Pretty sure you will need to create a CNAME record www for this to work.


#3

Hi thanks Andy. Trying to contribute towards secure web :wink:

Just added a CNAME
Name : www
Value : mydomain.com

Still not forwarding. Will it take time?


#4

It may take some time, yes. Also try clearing your cache. Your Page Rule syntax may also be an issue (not sure). Check out this article for more info on syntax:

https://support.cloudflare.com/hc/en-us/articles/200172286-How-do-I-perform-URL-forwarding-or-redirects-with-Cloudflare-

You mentioned you are using Wordpress in your other post. If you’re on Apache you could do this with mod_rewrite in your .htaccess (assuming you have access to your origin server) and save the Page Rule for something else…


#5

I used some page rules to do the same.
Make sure the rule you wrote is correct. For example, if you are also using https you will need more than one rule (I did it with three).


#6

I agree, if he can edit .htaccess he’d better save the page rules.
I used the page rules because, for that website, I couldn’t edit .htaccess.


#7

Yes, it was. I added $1 to the forwarding URL, as explained in the article. Now it’s redirecting :slight_smile:

Now the problem is it’s redirecting all www URLs to home page.

Yes using WordPress for blog (in subfolder), but can’t access server (.htaccess). The main site is in Asp.Net.


#8

Can you please tell the rules required. Thanks.


#10

Well, mine is working now with only one page rule :slight_smile: Maybe it needed some time, I purged the cache also.
Thanks!


#11

Glad you got it sorted. Page Rules are valuable, so good you were able to get it working with just 1.

On that subject, since you are running Wordpress, it’s advised to create a Page Rule for wp-admin area to bypass cache.

This video is pretty helpful (wish I had found it earlier) and covers the wp-admin page rule ~3:30 mark (along with some other tips):


#13

Yes Indeed it’s very helpful. One thing not able to get is when we have the option of “Always use HTTPS” under crypto then why we need to use one page rule to always use https. I am not using any page rule for this. Am I missing something?


#14

Forwarding URL - www.mydomain.com/* to https://mydomain.com/$1


#15

There’s no need for a page rule now that the Always Use HTTPS function is available. The video is just a little outdated.


#16

Unfortunately that is the case. Always use HTTPS was a very popular page rule that we wanted to make sure people were aware of (so we mention it a lot). We were eventually able to build it into the interface to make it even easier, but now are still going back and cleaning up the more confusing references.


HTTPS Page Rule
#17

@ryan could you please confirm that the syntax used in a message up here, mydomain.com/$
($ without a number) is correct? I have read all the examples in the documentation, and they only use $1, $2, etc.


#18

Wow, I didn’t know that Always Use HTTPS had been added to the interface. Great way to save at least a page rule… thank you for the tip!


#20

There needs to be a number associated with the $ or else it won’t match/replace correctly.


#21

As expected. Thank you for the confirmation.


#22

Typo mistake, it’s $1. Corrected.


#23

Hi Andy, bothering you again. Are you absolutely sure this is required? While reading more about CNAME, found that the purpose is different.

Isn’t the forwarding page rule enough for the redirection? In my case, maybe it was just cache purge required and after some time it start working.