Posts tagged add
Remove/Add the www? | SEO Tips:
3I'm sure you all have seen how some sites have www, some not, and do you? Because for most web developers this might not seep as an important thing, even though it is essential. If you don't have chosen one, you may end up with a www.yoursite.com with PR 3 and yoursite.com with PR 1 for example.
Now to avoid this you must first decide what do you prefer, with or without. I personally like it without...
Google tools:
A very important one, go to Google Webmaster Tools, claim your site, and there you have the option to display the www. in searches or not.
Using .htaccess
Another way is by using mod_rewrite in .htaccess.
To use this option, create or edit your existing .htaccess file and add the following lines:
Adding www:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Remember to change domain.com with your domain!
Removing www:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
More information about mod_rewrite and code snippets
Using php
Add the following script to the very top of your page, before anything else!
Adding www:
< ?php if (substr($_SERVER['HTTP_HOST'],0,3) !== 'www') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.urbanoalvarez.es'.$_SERVER['REQUEST_URI']); } ?>
Removing www:
< ?php if (substr($_SERVER['HTTP_HOST'],0,3) == 'www') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://urbanoalvarez.es'.$_SERVER['REQUEST_URI']); } ?>
Remember to change "urbanoalvarez.es" with your domain name.
Other ways
If you don't have php or the module mod_rewirte installed, you could do a simple 301 redirection.
If you don't understand it, or you find a better way of achieving this, please comment