Leave a Reply

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

1 Comment

  • Using .htaccess to redirect:This is the rough equivalent to your php script using a couple of lines in your .htaccess file. These lines use the Apache webserver’s mod_rewrite engine.# Add .www if missingRewriteCond %{HTTP_HOST} !^www\. [NC]RewriteRule ^(.*)$ http ://www.%{HTTP_HOST}/$1 [R=301,L]This file should be placed in your web site’s root directory or these lines can be added to one that already pre-exists.Note: This will not work correctly with subdomains without a bit more time and effort.Using Apache’s mod_rewrite has the added benefit of redirecting before php attempts to parse any page. Also, it saves having to add or include this extra script to every page on your site. Finally, the last benefit would be that it works for any type of document you are serving (ie: *.html) not just php documents.