Redirect a site to www using PHP
To redirect a site to url with www using PHP, you can use following PHP code
1 2 3 4 5 6 7 8 9 10 |
<?php $domainName = $_SERVER['HTTP_HOST']; if (strpos($domainName, 'www') === false) { header("HTTP/1.1 301 Moved Permanently"); $urlNew = 'https://www.' . $domainName . $_SERVER['REQUEST_URI']; Header("Location: $newUrl"); exit; } |
Add this code in your index.php file or another file included by index.php
See Redirect