How to redirect non-www URLs to www without htaccess
To redirect your yourdomain.com to www.yourdomain.com you have to write a simple code using php. Bellow code you have to paste at the top of your page.
<?php
$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.')
{
header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI']);
exit;
}
?>
$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.')
{
header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI']);
exit;
}
?>
And now when someone go to your domain like yourdomain.com he will be redirected to www.yourdomain.com.

Comments ( 0 )
Subscribe Latest Information
Categories
Most Popular Posts
How to Withdraw Money from ATM Machine 7steps 1182374 Views
How to Create Chat Application in Android Studio 152899 Views
How to Create a Shopping Cart Application in Android 116236 Views