Redirecting non-www to www with .htaccess

Redirecting non www to www with .htaccess
Redirecting non-www to www with .htaccess

If you ever point your www. record to another server you will want to setup a redirect for your domain without www. to point to www.

Edit your .htaccess file and add the following code...

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

This is also useful when using a CDN service such as CloudFlare.


Share this page:


Was this article useful? Have any suggestions or improvements to the information?

Also Read

How do I transfer my domain hosting to Ultra Web Hosting?

You will need to go to your registrar (where you registered your domain name) and modify the...

Clearing DNS Cache

When changing hosting providers or making DNS changes you may want to speed up the process of...

DNS Report Tools

To track down DNS related issues there are many websites available to assist you in isolated...

What is a domain name pointer or parked domain?

A domain name pointer is a domain name which simply points to your account. In other words,...

I am having problems with my current registrar transferring the domain to you.

If you have unlocked the domain with the current registrar, clicked on the confirmation link in...