How to Easily Redirect Non-www to www URLs

6 months ago 75

As a website owner, you might ponder whether using a www or non-www domain is merely a matter of user preference. While a non-www domain may seem simpler, it has drawbacks, including SEO implications and cookie control limitations. Redirecting non-www URLs to www can mitigate these issues and streamline your site’s performance. In this guide, we’ll explore three straightforward methods to achieve this redirection.

Why Redirect Non-www URLs to www?

Before delving into the redirection methods, let’s understand why it’s beneficial to redirect non-www URLs to www:

SEO Enhancement: A www domain helps consolidate ranking power and avoid duplicate content issues, boosting your site’s search engine optimization.

Cookie Control: With a www URL, you gain better control over cookies, which can improve website performance and reduce HTTP requests.

Overload Protection: Redirecting traffic from non-www to www enables better load distribution and server management, ensuring smooth website accessibility.

Redirecting Non-www URLs to www

There are various approaches to redirect non-www URLs to www. Here, we’ll explore methods suitable for different hosting environments:

hPanel (or Equivalent Hosting Control Panel):

  • Access your hosting account’s control panel.
  • Navigate to the File Manager and locate the .htaccess file.
  • Insert the following code snippet:
RewriteEngine On RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
  • Save changes to apply the redirection.

cPanel (or Equivalent):

  • Access cPanel and navigate to the Redirects section.
  • Choose the Permanent (301) option and specify the non-www URL to redirect.
  • Set the redirection target as the www version of your domain.
  • Save the redirection settings to implement the change.

Cloudflare:

  • Log in to your Cloudflare account and access the Rules tab.
  • Create a page rule for your non-www domain, specifying a 301 permanent redirect to the www version.
  • Save and deploy the rule to activate the redirection.

NGINX (for VPS Hosting):

  • Access your server via SSH and navigate to the NGINX configuration directory.
  • Edit the nginx.conf file and add a server block to handle redirection:
server { server_name yourdomain.com; return 301 $scheme://www.yourdomain.com$request_uri; }
  • Restart NGINX to apply the changes.

Apache (for VPS Hosting):

  • Enable mod_rewrite and .htaccess support on Apache.
  • Edit the virtual host configuration file to allow .htaccess overrides.
  • Create or edit the .htaccess file in your website’s root directory and insert the redirection rules.
  • Restart Apache to enable the redirection.

Conclusion

Redirecting non-www URLs to www is a simple yet effective strategy to streamline website management and enhance SEO performance. Whether you’re using a hosting control panel, a CDN like Cloudflare, or managing server configurations directly, implementing this redirection ensures a seamless user experience and strengthens your website’s online presence. Choose the method that suits your hosting environment and effortlessly redirect non-www traffic to the www version of your website.