Redirecting your www to your non-www website. A how-to guide.
Published on June 21, 2015
Published on Wealthy Affiliate — a platform for building real online businesses with modern training and AI.
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:
Ready to put this into action?
Start your free journey today — no credit card required.
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.
Share this insight
This conversation is happening inside the community.
Join free to continue it.The Internet Changed. Now It Is Time to Build Differently.
If this article resonated, the next step is learning how to apply it. Inside Wealthy Affiliate, we break this down into practical steps you can use to build a real online business.
No credit card. Instant access.