PHP Redirect – 2 domains pointing to one website
posted in PHP TutorialsMy 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.
-
Great so you don’t lose the linkjuice? For example if you have two sites: 1st site has 3 backlinks and 2nd site has 2 backlinks. By doing a redirect do we now have 5 backlinks and the link juice from both sites?
-
Yeah, you now have 5 backlinks for the one site that is receiving the redirect.
Brian Yerkes’s last blog post..Logo Design Case Study | Bayfront Bistro
-
Hi,
The fact the sites are PHP isn’t actually relevant here is it? The above would work for any Apache based site?Paul’s last blog post..Martello Towers of the East Coast
-
Paul,
Yes, I presume so. I have limited knowledge in php and apache servers but I don’t see why it wouldn’t work.
Brian Yerkes’s last blog post..Why CrowdSpring Owners Should Be Ashamed of Their Business
-
Thanks for this useful post – I’ll be sure to bookmark your blog.Best regads. soccer reality


