Redirecting www to non www


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


#24

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:
*www.4ndy.us/* --> https://4ndy.us/$1

I deleted the www CNAME record. If I try and go to www.4ndy.us 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.


#25

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?


#26

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


#27

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

Redirect to www

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

view rawgistfile1.apacheconf hosted with by GitHub

Redirect to non-www

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

{redacted}