redirect domain.com to www.domain.com

Sometimes its needed for site functionality for the www to appear in the URL for some scripts and to just make the site cleaner and more consistent and even improve search engine optimization. You can do so with htaccess!

WARNING!  MAKE A BACKUP OF YOUR FILE FIRST AND FOREMOST FOR QUICK REVERSAL.

Then these lines to the top of your root .htaccess file:
# BEGIN CODE #
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^m3xs\.com$ [NC]
RewriteRule ^(.*)$ http://www.m3xs.com/$1 [R=301,L]
# END CODE #

If you don't have a current .htaccess file, just create a plain text document in notepad or textedit and ake sure you save it as:
.htaccess
Upload this .htaccess to your site's main directory where your main index file is.

Also, TEST TEST TEST! Make sure you didn’t get a typo in your entry.

In this example, the above URL:
http;//m3xs.com/ will auto switch to http://www.m3xs.com/
Naturally, replace m3xs.com with your actual domain name as this is an EXAMPLE only.

Tip!  Make sure you click a few links inside your site.  If you have WordPress or other PHP scripts, make sure they are configured to MATCH your htaccess settings, otherwise, your site could end up in a redirect loop.

  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Domain redirect

So you bought another domain name that matches one you currently have.  You shouldn’t...

restrict by IP or password

I find myself tired of having to answer the pop up authentication box to view my control panel...

rewrite base

Top directories can break functionality on sub directories. Case in point:Scenario: WordPress...

rewrite non SSL to SSL

Want to force users to use SSL on your site?Add this code to the top of your .htaccess file, edit...

Traffic source redirect

Need to redirect source traffic to another domain?  Well, if you can’t modify the link...