How to redirect non-WWW traffic to WWW using Mod Rewrite

4

If you are looking to send people to www.yourdomain.com, when they type in yourdomain.com then you can use mod rewrite in Apache to get this done for you.

Use the code below in your .htaccess file:

RewriteEngine On

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

  1. Hello Jake, thanks for sharing this tips, i never knew about this, Well, we have recently launched a contest for graphic designer. To enter into contest you must have 10 decent forum posts.
    We are looking for designers who can make the best vBulletin forum theme including logo with great exceptional imagination skills and you can win Dell XPS M1530 Laptop and more.

    Hope this might be of some interest to you.

  2. Heh, you steal this code from my remotv apache configs? jk

    It is actually safer to do it in the config files though.

LEAVE A REPLY