/ Published in: PHP
URL: http://www.bradino.com/php/force-www-subdomain/
Sometimes you do not want users to access your domain without the www. If you want to force www.yourdomain.com and redirect yourdomain.com to www.yourdomain.com here is a simple way to do it.
Expand |
Embed | Plain Text
Comments
Subscribe to comments
You need to login to post a comment.

and if you want to apply it globally across the entire website without modifying every php file (and you're on a linux server), you can use .htaccess
RewriteEngine On RewriteCond %{HTTPHOST} !^www.YOURSITE.com [NC] RewriteCond %{REQUESTFILENAME} !-f RewriteRule ^(.*)$ http://www.YOURSITE.com/$1 [R=301,L]
That will redirect everything (html, php, jpg, gif, pdf, etc.. EVERYTHING) and will also invoke a 301 redirect header to tell search engines to gracefully update their links when visited so you don't lose your SEO rank.
ok not sure why it didn't preserve the "new lines"...