PDA

View Full Version : Mod Rewrite - adding the www


Illustrious
01-12-2007, 04:33 AM
I'm just wondering what to put in the .htaccess in order for me to rewrite URLs to include the www.

For example, I want to change about example.com to www.example.com, how would I go about doing that?

Dismounted
01-12-2007, 05:02 AM
Add this to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^YOURDOMAIN.COM$ [NC]
RewriteRule ^(.*)$ http://www.YOURDOMAIN.COM/$1 [R=301,L]
Of course, replace YOURDOMAIN.COM with your domain.

Illustrious
01-12-2007, 05:05 AM
That worked. Thanks. Now, I noticed it only rewrites the initial URL, is there a way for it to add it to each subsequent URL?

For example, change example.com/forums to www.example.com/forums or example.com/12324 to www.example.com/12324.