+254725682556 +254725052660 info@ziprof.co.ke
Client Area

General Knowledge

How to Redirect www to Non-www (or Vice Versa) on Your Website

By default, www.yoursite.com and yoursite.com are treated as two different addresses by browsers and search engines, even though they point to the same hosting account. If both versions load without a redirect between them, you end up splitting your traffic and your SEO value across two URLs instead of one. The fix is a single redirect rule that sends every visitor and every search engine crawler to the version you actually want to use.

Why Consistency Matters

Search engines can index both the www and non-www versions of your pages as separate, duplicate content, which weakens your ranking signals instead of concentrating them on one URL. It also affects how your site looks to visitors: links, business cards, and social media shares should all point to the same consistent address.

Step 1: Choose Your Preferred Version

Decide once, and stick with it everywhere (Google Search Console, your marketing materials, your email signature). Neither version is technically better. Most Kenyan small business sites choose the shorter non-www version, but it comes down to preference.

Step 2: Add the Redirect to Your .htaccess File

This is done the same way whether your hosting account is on cPanel or DirectAdmin, since both use the same .htaccess file to control how your web server handles requests.

  1. Open your control panel's File Manager and navigate to your website's root folder (usually public_html).
  2. Make sure hidden files are visible, since .htaccess starts with a dot. Most file managers have a Settings option with a Show Hidden Files checkbox.
  3. If a .htaccess file already exists, right-click it and choose Edit. If it doesn't exist yet, create a new file named exactly .htaccess.
  4. Add one of the following blocks near the top of the file, above any existing WordPress or CMS rewrite rules.

To redirect www to non-www:

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

To redirect non-www to www instead:

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

Replace yoursite.com with your actual domain name in both the condition and the destination, then save the file.

Step 3: Confirm the Redirect Works

  1. Open a private or incognito browser window, so cached results don't give you a false result.
  2. Type in the version of your address you want to redirect away from (for example, the www version if you chose non-www).
  3. Confirm the browser automatically lands on your preferred version and the address bar updates to match.
Before editing .htaccess, copy its existing contents somewhere safe first. A mistake in this file, like a missing bracket or an extra character, can take your entire website offline until it's corrected.

If you're setting up this redirect alongside forcing HTTPS on your site, add both sets of rules to the same file so visitors reach the correct address in one hop instead of bouncing through multiple redirects. For more on how the rest of this file works, see What Is a .htaccess File and What Can You Do With It?