Redirecting a subdomain or addon domain

Published in Joomla
PastedGraphic-1.png
 
If you have shared hosting and are using Joomla, Drupal or Wordpress you might find you need to redirect incoming traffic through the addon domain or sub domain to the correct URL.
 
If you don't redirect it you could find that Google might find its way into the domain via it's subdomain address and index that as content of your main hosting account. This will have the effect of duplicating content in its search engines and you site might suffer in Google rank.
 
Basically if you have: "www.main-hosting-account.com" and "www.main-hosting-account.com/subdomain"  or  "www.main-hosting-account.com/addon-domain", then it may be handy to visit through this address before going live, but when you do go live you might want to redirect the add-on domain.
 
To redirect a subdomain or addon domain simply edit the .htaccess file and add the following code (you can find in the root directory of you subdomain/addon domain). Note: NOT in root directory of your main account. If you can't find one, simply create a text file, paste in the following code and name the file ".htaccess" (without the quotes, and yes, it has no file extension) and upload it to the root directory of your subdomain or add-on domain. IMPORTANT: You will need to change "your-real-domain" with the real top level domain name that you axon domain or subdomain should redirect to.
 
 
Options +FollowSymLinks
 
RewriteEngine On
 
RewriteCond %{HTTP_HOST} !^www\.your-real-domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.your-real-domain.com/$1 [R=301,L]
 
 
 
Your hosting provider might have rules about Sym Links, so if it doesn't work ask your hosting provider if you need to setup symlink permissions.
 
With a bit of luck. Pasting the above code in the .htaccess will correctly redirect subdomain or add-on domains. Good luck!
 
This should also work for redirecting subdomain or add-on domain using the following scripts: WordPress, Chyrp CMS, b2evolution, Textpattern, NucleusCMS, Geeklog, Noah's Classifieds, SugarCRM, Feng, Front Accounting, vtigerCRM, Simple Invoices, Joomla, 
ocPortal, Drupal, MODx, Mambo, XOOPS, PHP-Nuke, phpwcms, ShopSite, PrestaShop, Magento, CubeCart, OSCommerce, Zen Cart, AgoraCart, OpenCart, TomatoCart, Moodle, 
Chamilo, LimeSurvey, phpFormGenerator, AdvancedPoll, vBulletin Forums, Simple Machines Forum, phpBB, bbPress, PunBB, Vanilla Forums, GBook, Lazarus, osTicket, Live Chat, phpFreeChat, X7Chat, Dada Mail, phpList, poMMo, Coppermine, Gallery, Zenphoto, Piwigo, Pixelpost, 4images, Mantis, PHProjekt, Gregarius, SimplePie, elgg, WikkaWiki, DokuWiki and PmWiki