Adding www to all urls for a domain

| | Comments (0)
On pretty much every of my projects (which I run on apache) I have the need to automatically rewrite all requests without www to the corresponding adress with www. It's simply, and this is the code I use (over, and over again). It rewrites (for example) http://luradittbarn.se to http://www.luradittbarn.se. If you request a page (i.e) http://luradittbarn.se/archives.html to http://www.luradittbarn.se/archives.html

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]


The code is originally from Webmasterworlds forum (a very old thread, which can be found here)

Leave a comment

About this Entry

This page contains a single entry by Niklas Bivald published on October 23, 2008 7:22 AM.

Mjukstart: www.luradittbarn.se was the previous entry in this blog.

Programming for the iPhone is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en