I am using GoDaddy Hosting, I would like to know how to redirect www url to without www url or without www url to with www url
You can try following methods to redirect non www url to www url or www url to non www url for your GoDaddy 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
<3>GoDaddy Account
non www to www
1. Login to your Godaddy Account
2. Click on “Launch” to expanding your all domain list
3. tick on that domain which you want to forward
4. Mouse hover on “Forward” button and click “Forwarding Domains”
5. “FORWARDING AND MAKING” popup will be appear and click “Add one now”
6. first select “http://” and then enter your site address with “www”. After that select “301 (Permanent)”, in FORWARD SETTINGS then selcet “Forward only”, then click on “ADD” button.
7. Finally hit on “SAVE” button to save your settings.