I am using Hosting24 Hosting, How can I redirect www url to without www url or without www url to with www url
Here are some methods can help you redirect non www url to www url or www url to non www url for your Hosting24 Hosting
.htaccess
non www to www
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
www to non www
RewriteEngine On RewriteCond %{HTTP_HOST} !^yourdomain\.com RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
PHP
www to non www
if (substr($_SERVER['HTTP_HOST'], 0, 4) === 'www.') { header('Location: http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 's':'').'://' . substr($_SERVER['HTTP_HOST'], 4).$_SERVER['REQUEST_URI']); exit; }
non www to www
if (substr($_SERVER['HTTP_HOST'], 0, 4) != 'www.') { header('Location: http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 's':'').'://www.' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit; }
cPanel
www to non www or non www to www
Home >> Domains >> Redirects >> Add a redirect