Redirecting your www to your non-www website. A how-to guide.

3
133 followers
Updated

When setting up a new website (which I am doing now), it's important to ensure that all your traffic is being sent to your primary landing page. While this may seem like an obvious concept, most people fail to properly setup a redirect between http://example.com and www.example.com

While both are considered to be the same website, some servers may see them as different as www.example.com is technically a subdomain.

Why should you care?

Well the most obvious reason is that you don't want servers to consider your content as duplicate. Also, when it comes to analyzing data (from Google Analytics for example) it's best to have everyone landing on the same page so as to simplify your task.


To complete this relatively simple task you'll need:

1) FTP program (example: Filezilla)

2) Google Webmasters Tools account

3) a text editor (example: notepad++)


We need to do 3 things to effectively ensure that all our traffic is landing at the same page.

First: Be consistent when building internal links, new posts/pages. If you choose to use http://example.com, then never use the www. subdomain on your website. By being consistent, you will save the server from redirecting your traffic which should decrease your loading times. You should also look into your theme settings to make sure that your permanent link settings are consistent with your choice.

Second: Open a Google Webmaster's Tools account (if you haven't already) and add both http://example.com & www.example.com to it. Once you see both in your console, go into the "Site Settings" of your preferred choice and select it under the "Preferred Domain" section. This is letting Google know of your preference when they index your site and allows them to classify both the www and the non-www domains as the same (thus reducing crawl errors and unnecessary redirects).

Third: Modify your .htaccess file to 301 redirect all traffic to your preferred domain. See below on how to accomplish this.



BACK UP ANY FILES THAT YOU INTEND TO OPEN/MANIPULATE! While we're not doing any major "coding", messing with the .htaccess file could break your site or have other unwanted effects. Always backup everything.

1) Obtain your FTP login information from WA by going to "Site Manager" and then clicking on the "Details" (gears icon).

Alternatively, you can use this url:

https://my.wealthyaffiliate.com/websites/details/yoursite.com

2) Open your FTP program. To access your website you'll need:

Host: yoursite.com

Username/Password: Provided by WA (see # 1 above)

3) Once logged in, you will be in your root directory (/). You should see 4 folders:

cgi-bin / error_docs / httpdocs / httpsdocs

Double click on the third choice (httpdocs)

4) In httpdocs, you will see your .htacess file. First, download (or view/edit) and backup the unedited version. Keep this file in a safe location for future reference. I cannot stress how important this is.

A typical .htacess file looks like this (copied from my fresh install)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

5) Add some code to ensure the redirect.

If you are wanting to redirect www to non-www then add the following code at the bottom of your .htaccess file

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

Make sure you only replace the word example with your exact url. Don't change anything else.

If you are wanting to redirect non-www to www then add the following code at the bottom of your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nocase]
RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301]

Again, making sure you only replace the word example with your exact url. Don't change anything else.

Example of a changed .htaccess file (after a fresh WP install):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourwebsite.com [NC]
RewriteRule ^(.*) http://yourwebsite.com/$1 [L,R=301]

"#redirect www to non-www" is simply an annotation for future reference. It isn't doing anything else.

The redirect type is 301 (moved permanently) which is preferred by search engine spiders and shouldn't affect search engine rankings or significantly reduce link juice. In most situations, you really should be using a 301 redirect.



That's it! If you're website isn't already forwarding www to your non-www domain or vice versa, you should really consider doing this. It's quite easy and has numerous advantages.

Again, please remember to back-up your files before your start changing them. It's super important.

If I missed something or made an error, please comment or PM me. I am by no mean a professional computer programmer and do not accept any responsibility if your site has issues after following my guide.

Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training

Recent Comments

9

Excellent piece of advice. will definitely check this is sorted.

I understand that WA redirects all www's to non-www's thru their servers. Would you know why?

Hmmm I'm not sure. Maybe for the above mentioned benefits of having all your traffic going to only one landing page. It's funny because my www website wasn't redirecting to my non-www which is why I made this training.

Yes, Stephane, I can see the redirect when I go to my website from WA, but yours does not redirect. Is your website hosted by WA? Why do you want it to go to the non-www?

Which one does Google prefer? They recommend all three be listed with the HTTPS protocol as the third one. They want to know which one you prefer??? How do you choose? I am still new at all this.

Thanks for the training

No problem Divican! I was hoping to post it as training but I haven't been here for 3 months. I'll probably move it over later... being able to break it down into sections makes following directions way easier.

Yes I see it as a training. No problem your points are clear enough to follow and remember to post it as a training after your 3 months here. Thanks

Thank you for the training!

When you are able to re-create this as training, leave this blog post as is, AND create the new training, broken out into sections with a little more explanation

by having both the blog and the new training, you have the potential to reach and help more members here on WA

all the best,

Thank you for the input. I definitely wanted to add screenshots and will do so when I can organize them better. Thanks again.

See more comments

Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training