Force a www Prefix


You want to force the World Wide Web prefix of your domain name, even though a page was requested without it. For example, if you would like all requests to be redirected to


Solution from Alister Cameron. It works for Linux/Unix and requires .htaccess file access.
In the web root directory .htaccess file, add the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]RewriteCond %{REQUEST_URI} ^/[^.]+[^/]$

RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

If you are using WordPress, those rules should come before the standard WordPress rules.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.