The following website URL’s may seem like they are the same page to you, but to a search engine they might actually seem like two different pages:
http://yourblog.com
http://www.yourblog.com
Search engines may think www.yourblog.com and yourblog.com are two different blog sites. You should set up a permanent redirect (technically called a “301 redirect”) between these sites. Once you do that, you will get full search engine credit for your work on these blog sites and it will improve your search engine optimization and the SEO rankings.
A simple edit in your index.php file in your blog root directory will fix the permanent redirect for you. This is the text you need to paste into your index.php (replace “yourblog” with your blog URL without .com). So for http://www.yourblog.com you would only write yourblog as seen below:
// non-www redirect
if (strstr($_SERVER['SCRIPT_URI'], “http://yourblog”) !== false) {
$newLocation = str_replace(“http://yourblog”, “http://www.yourblog”, $_SERVER['SCRIPT_URI']);
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.$newLocation);
}
When this is saved to your index.php, all your visitors will be redirected to www.yourblog.com even if they enter yourblog.com in their browser address bar.
As I have mentioned before you should add your blog to Google Webmaster Tools. There you can confirm this permanent redirect directly with Google.
Login to your Google Webmaster Tools account, go into “Tools” and choose “Set Preferred Domain”. There you can associate a preferred domain with your blog site, to always or never show the leading “www.” in Google’s search results.
Join thousands of bloggers and get all my blogging tips for FREE! Subscribe to HowToMakeMyBlog via RSS or via e-mail.
If you liked this article, you may also like:
Why I run my blog on Thesis Wordpress Theme
Thesis theme gives my blog a professional, clean, easy-to-read layout and SEO friendly design. Thesis makes it simple to make your own blog unique. See more details and get your own Thesis today.
{ 7 comments }
Marko,
I used this script with no issues on my Blue Grace template. Then when the author updated the theme to vs 3.0 (and I did too), now anywhere i put the script in the index.php…it shows up on the web page. If I move it in somewhere else in the index.php….it shows up in the page in that area. Any suggestions?
Thanks.
@ Paul – I am not sure what the problem is. Try to put something like this into your index.php:
< ?phpif (substr($_SERVER['HTTP_HOST'],0,3) != ‘www’) {
header(’HTTP/1.1 301 Moved Permanently’);
header(’Location: http://www.’.$_SERVER'HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>
Marko,
Ok, I see your PHP open/close tags are different now and match the Index.php tags. But, where in your script do I place my URL? I’m a bit of a php noob.
Thanks
@Paul – In that one you do not need your URL. I am not either, I had my script done from a friend, so I was looking for “301 redirect wordpress” on Google now for you.
Ok, thanks. You did not have to do that…I could have done it. LOL. I just thought I’d check the source. I’ll give it a try and see what happens.
Thanks again.
Thanks for the easily understandable article.
Thanks Marko for pointing out the importance of this issue. I have been aware of it, but never paid much attention. Though I run Drupal, I have researched how to do redirect, and fixed the issue in two minutes.