title: redirect to site if www part is missing using PHP
body: <p>I asked the same question <a href="https://stackoverflow.com/questions/6785310">Redirect to site if WWW part is missing</a> but the answer did not helped in my case, as i was unable to get to change the CNAME and .htaccess also failed.<br>
  The only option left is to use PHP.<br>
  Can anyone help me ?  </p>
  
  <p>If someone tries to browse example.com or example.com/ or so the PHP will redirect it to www.example.com/..</p>
  
  <p><code>edit</code></p>
  
  <pre><code>SetEnv TZ Asia/Calcutta 
  
  ErrorDocument 400 /error.html
  ErrorDocument 401 /error.html
  ErrorDocument 403 /error.html
  ErrorDocument 404 /error.html
  
  &lt;ifModule mod_php4.c&gt;
   php_value zlib.output_compression 16386
  &lt;/ifModule&gt;
  
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine on
  RewriteBase /
  
  RewriteRule ^home$ home.php [L]
  
  RewriteRule ^credit$ credits.php [L]
  RewriteRule ^credits$ credits.php [L]
  
  RewriteRule ^profile/(\d+)/?$ profile.php?id=$1 [L]
  RewriteRule ^user/(\d+)/?$ view_profile.php?id=$1 [L]
  
  RewriteRule ^blog/?$ blog.php [L]
  RewriteRule ^blog/(\d+)/?$ blog.php?id=$1 [L]
  RewriteRule ^blog.php/(\d+)/?$ blog.php?id=$1 [L]
  RewriteRule ^blog/(\d+)/([A-Za-z0-9-_\[\]]+)/?$ blog.php?id=$1&amp;title=$2 [L]
  RewriteRule ^blog.php/(\d+)/([A-Za-z0-9-_\[\]]+)/?$ blog.php?id=$1&amp;title=$2 [L]
  
  RewriteRule ^blogbyauthor.php/(\d+)/?$ blogbyauthor.php?uid=$1 [L]
  RewriteRule ^blogbyauthor/(\d+)/?$ blogbyauthor.php?uid=$1 [L]
  RewriteRule ^blogbyauthor/(\d+)/?$ blogbyauthor.php?uid=$1 [L]
  
  RewriteRule ^blog_by_category.php/([A-Za-z0-9-_\[\]]+)/?$ blog_by_category.php?category=$1 [L]
  RewriteRule ^blog_by_category/([A-Za-z0-9-_\[\]]+)/?$ blog_by_category.php?category=$1 [L]
  &lt;/IfModule&gt;
  </code></pre>