Few weeks ago I wrote how to remove WWW from domain with .htaccess. In some cases or hosting plans it’s not possible to view or use .htaccess file (e.g. some low cost or free hosting providers).
Solution is PHP code which redirects all www requests to non www page. Since You are (should) use some general configuration or header file in Your web application, you can include this PHP code (very top of php page):
<?php // Removing WWW from URI with PHP http://simplemediacode.info/?p=136
if ('mediabox.lv' !== $_SERVER['HTTP_HOST']) {
header('Location: http://mediabox.lv' . $_SERVER['REQUEST_URI'], null, 301);
}
?>
It use build-in PHP header() function to redirect all requests to another page, in this case: non-www domain.
Simple!
