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]

Categories: WebWordPress

4 thoughts on “How to redirect non-WWW traffic to WWW using Mod Rewrite”

Designer Marketplace · June 21, 2009 at 3:23 pm

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.

Kyle W · June 26, 2009 at 1:16 am

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

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

jrutter · June 28, 2009 at 1:28 pm

Safer, how so? And which config files?

    Kyle · August 6, 2009 at 1:08 pm

    Hey,

    Sorry for the extremely late reply. It's basically just that people can do bad stuff.

    http://www.petefreitag.com/item/505.cfm

    There's a link mentioning the sentiment. You could argue I'm just being a security-paranoid person, and you might have a good argument! Whatever works for you is fine, though.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Web

Angular JS Magazine on Flipboard

I have been working with AngularJS for about a year now, trying to learn as much as I can about this growing framework. It’s been a wild ride and I’m going to post a summary Read more…

Top 5

Top 5 Articles : Week of November 25

During the the week of November 25th, I really started to dive into Angular JS. My top 5 articles of the week are mainly about AngularJS, an MVC framework by Google. #1 : AngularJS WebInspector Read more…

eCommerce

How to implement Bronto Email JavaScript Conversion tracking in Google Tag Manager

This tutorial will show you how to setup Bronto Advanced JavaScript Conversion tracking using Google Tag Manager. Bronto Advanced JavaScript tracking gives you more visibility to all of the products that customers are purchasing, then Read more…