Redirect No Host to WWW Host

Hack on September 23rd, 2011 No Comments

Here is the code required to redirect no host to a www host. PHP and ASP versions of the code are included.

PHP

 PHP |  copy code |? 
1
<?php
2
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
3
 header('HTTP/1.1 301 Moved Permanently'); 
4
 header('Location: http://www.'.$_SERVER['HTTP_HOST']
5
 .$_SERVER['REQUEST_URI']);
6
}
7
?>

ASP
 ASP |  copy code |? 
1
<% if Request.ServerVariables("HTTP_HOST") = "domain.com" then Response.Redirect("http://www.domain.com") %>

Tags: , , , , ,

No Responses to “Redirect No Host to WWW Host”

Leave a Reply