drbill1
asked on
Prepend www to URL using PHP
I have a WordPress blog hosted on IIS and I've been trying to get ISAPI_Rewrite to work so that I can prepend www to the URL. It isn't working after 3 hours, so I just want to use PHP redirect to get it working. I've done it before with ASP (which I've included) but I don't know PHP well enough to translate this code. Can you do it?
<%
If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www."
& Request.ServerVariables("HTTP_HOST")
& Request.ServerVariables("REQUEST_URI")
Response.End
End if
%>
I forgotthe ; at the end of header("Status: 301") and "exit;" in place of "Response.End"
... The correct should be:
... The correct should be:
<?
if (strpos($_SERVER['SERVER_NAME'], "www")===false)
header("Status: 301");
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']");
exit;
}
?>
or
<?
if (strpos($_SERVER['SERVER_NAME'], "www")===false)
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']");
exit;
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yeah, 3 little typos in just one question... Might be the record :P
Thanks for the help :)
Thanks for the help :)
ASKER
Worked perfect with the corrected typos, thanks!
Open in new window