by Brian

PHP Redirect – 2 domains pointing to one website

My company was recently hired to take over the management of the Fort Myers Beach Chamber of Commerce website, and as we dugg thru the site, the databases and the emails, I realized that the Chamber had two domain names, and 2 identical websites. FortMyersBeach.org, and Fmbchamber.com. Not good! Not good because the all of the backlinks, page rank and content was being shared over two websites, hindering the website’s search engine performance.

So, we had to figure out a way for both domains to still show the Chamber website, but to not lose the rankings and link juice for either website. As the websites are in PHP, we decided that the best way to go about this process was with .htaccess file re-directs. Pretty simple implementation involved as you can see from the small snippet of code below. All you have to do is add this code to your .htaccess file (create one if you do not have one already) , and yes, that is a period before the “h”.

.htaccess files only work on Apache servers so before you use them make sure your server allows this file.

Code:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.fmbchamber.com [nc]
rewriterule ^(.*)$
http://www.fortmyersbeach.org$1 [r=301,nc]

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^fmbchamber.com [nc]
rewriterule ^(.*)$
http://www.fortmyersbeach.org$1 [r=301,nc]

It is pretty obvious what is going on in this code. I am telling the server to permanently redirect any fmbchamber.com and www.fmbchamber.com url’s to www.fortmyersbeach.org. I threw this together real quick and I’m sure hardcore php developers have a much cleaner way of coding this, but this snippet works perfectly for its purpose.