How To Do a WWW Redirect

The web is a dynamic environment in which pages constantly flow and change. At some point, you might wish to change or move to a new web address, rebrand your business or extend it. This is where redirects come in: redirects enable you to make the best out of your web history.

Why You Should Do a Redirect in the First Place?

Let us assume you have a business website that has been online for the past 7 years or more. Your website has achieved great authority, is well positioned in the SERPs (search engine results pages) so it has great traffic. Not to mention, you did tons of social media marketing, maybe even offsite marketing to promote it, so people have basically got used to the brand. But what if you’d move to a new page, a new domain? What would happen then? Well, you would basically have to give up on all that you have achieved and spend $$$ a lot more on AdWords, remarketing, promotion etc.

Yet again, you could save all the pain and $$$ by using a Redirect service. You have more Redirection services to opt for:

  • 301 – signifies “moved permanently” and this one is most recommended for search engine optimization
  • 302 – signifies “found” or “moved temporarily”
  • Meta refresh

What Is the Deal with a WWW Redirect?

If you want to do a redirection of canonical hostnames (meaning you want the page to redirect the user to a – notice the first one does not contain a “www” in front of domain name), then you have to do a WWW Redirect. This directive tells the server (Apache or other kind) to examine the host that is being accessed by the web user. If the host is not the then it must be redirected to the page containing the “www” directive, without disrupting the file location. Meaning all your files on the old page (without the “www” directive) will be preserved on the new page (the one with the “www” directive).

What Is the Code Used for a WWW Redirect?

Coding time – steps to follow:

  1. mod_rewrite must be enabled on your webserver in order to use www redirects.
  2. Make sure that this line appears in your .htaccess file, above the redirect rules.
  3. The following rules will redirect the non-www to the www version of your website:

RewriteCond % {HTTP_HOST} ^ [NC]

RewriteRule (.*)$$1 [R=301,L]

Or you could use:

RewriteCond % {HTTP_HOST} *!* ^www*.example\.com [NC]

(Note: Adding the exclamation point negates the comparison, and encourages the Apache to perform RewriteRule, “if the host is not”.

RewriteRule (.*)$$1 [R=301,L]

Sergiu Draganus
CEO - GeoRanker

Sergiu Draganus is an Entrepreneur, CEO & Co-Funder of GeoRanker and Conference Speaker - open to approach any new type of analysis and suggestions related to Local SEO.


Copyright 2024 © GeoRanker. All rights reserved.