301 Redirects for WordPress
Updated: PHP code has been updated after realizing that some of the code had been stripped by the WordPress WYSIWYG editor.
As I mentioned in my The Great Thing About Blogging post, I made the mistake of assigning multiple URL’s to this site in an attempt to make it easier for people to go to my site. Then I came across Chris Garrett’s posts about Plugin for WordPress WWW Issues and Search Engine Friendly Redirects and was introduced to the disadvantages of having multiple URL’s generating duplicate content on Google. And even if you haven’t purposely assigned multiple URL’s to your site, you can still get dinged because Google has trouble distinguishing between www.theclosetentrepreneur.com, theclosetentrepreneur.com, and theclosetentrepreneur.com/index.php and may treat them as 3 different pages – again leading to duplicate content.
So the first thing I did after doing my research was download and activate Mark Jaquith’s Enforce www. Preference WP plug-in. The nice thing about this plug-in is that it redirects visitors to the www or non-www URI you’ve specified in WordPress’s general options, and strips off index.php thus killing two birds with one stone. *As a side note, I’m not completely sure how to determine whether your www or non-www URL should be used; in my case my non-www URL actually registered a Page Rank whereas my www URL did not.
The next thing I did was redirect any pages or links from closetblog.com or www.closetblog.com to theclosetenrepreneur.com by using the following PHP code:
<?php if ( ($_SERVER['HTTP_HOST'] == "www.closetblog.com") || ($_SERVER['HTTP_HOST'] == "closetblog.com") ) {
//Redirect
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Status: 301 Moved Permanently' );
header( 'Location: http://theclosetentrepreneur.com/' );
}
else {
print "Please update your links to http://theclosetentrepreneur.com/";
}
exit(); // This is optional but suggested, to avoid any accidental output
?>
Be forewarned that I’m not versed in writing PHP code, so it may not be properly optimized or correct. All I did was modify the code I found in Chris Garret’s aforementioned post, and pointed www.closetblog.com and closetblog.com to the /redirect/index.php script on my root directory containing the code – and so far it has been working.
Anyways, I thought this info might be useful to those who have run into the same issues with their site.
Sincerely,
The Closet Entrepreneur
» This entry was filed under General and tagged with: Advice, seo, Wordpress
2 Comments
Will Ashworth
Thanks for reporting on this. I was looking for a 301 solution for WordPress and almost had to write my own!
Thanks,
Will Ashworth
SEO Reviews
Dec 7th, 2006
TOMAS
Hey Will, I’m glad you were able to make use of my 301 “wrap up”, although the credits for the original code should go to Chris Garrett of Performancing.com. 🙂
Dec 8th, 2006
Leave a Comment