prob 90% of the problems posted on this board that contain the use of header(),
are due to people sending headers after they have sent output.
ob_start() can fix thier problem. he prob just near rightfully assumed that was likely your problem. (i would have guessed the same)
it looks to me like your code should work. it might work too good though, if for example you using subdomains.
this would not fail when using subdomains, as it would only match the subdomain "www"
Code: Select all
<?php
if (isSet($_SERVER['HTTP_HOST'])) {
if (0 === strpos(strtolower($_SERVER['HTTP_HOST']), 'www.')) {
header("Location: http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
}
}
?>
but still, i think your code should work.
i would try doing this to see what the _SERVER variables actually contain. different configs can sometimes return unexpected results. HTTP_HOST may not even exist on your server....