How To Redirect From Domain.com To Www.domain.com Using .htaccess

How to Redirect from domain.com to www.domain.com

If you want all visitors to be automatically redirected from the non‑www version of your domain (domain.com) to the www version (www.domain.com), you can do this easily using an .htaccess file.

This method works on both Windows hosting (place the file in wwwroot) and Linux hosting (place the file in public_html).


Required .htaccess Rules

Create or edit your .htaccess file and add the following lines, replacing domain.com with your actual domain name:

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

What This Redirect Does

  • Forces all traffic to use the www version of your domain.
  • Improves SEO by avoiding duplicate content on www and non‑www URLs.
  • Ensures consistent URL structure for visitors and search engines.

After saving the file, the redirect takes effect immediately. You may need to clear your browser cache to see the change.


Learn More About Fast2host

Fast2host has been providing reliable UK hosting, domains, cloud servers and business email since 2002. Find out more about who we are:

About Fast2host →
Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 10550

Need more information or have a question ?