Redirecting www to non www


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).


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.


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.


Can you please tell the rules required. Thanks.


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


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):


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?


Forwarding URL -* to$1


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


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

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


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!


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


As expected. Thank you for the confirmation.


Typo mistake, it’s $1. Corrected.


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.


Hey, it’s no bother :smiley:

Well… I’m not absolutely sure - I can only tell you my results from testing.

I have a test site set up with the following forwarding rule:
** -->$1

I deleted the www CNAME record. If I try and go to my browsers give me an error (you can see for yourself). When the www CNAME record is present the forwarding rule works fine.

Based on my understanding, without the www CNAME present DNS will not resolve.


Could you help me, I’ve done everything and my domain does not work without “www” see the attachments, you look at me and see if they are correct?


Anyone get it working - if so. Can you please post what works for you instead of saying you have it working.


Simply put the following lines of code into your main, root .htaccess file.
In both cases, just change out to your own hostname.

Redirect to www

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

view rawgistfile1.apacheconf hosted with by GitHub

Redirect to non-www

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]