How to redirect Addon Domain -htaccess changes

SEO, Tips N Tricks 18 Comments

I recently added techofweb.com as an Add-on Domain to mine primary domain oceanofweb.com

Addon Domains can be accessed in following 3 different ways:
*www.addonDomain.com
*www.primaryDomain.com/addonDomain.com
*www.addonDomain.primaryDomain.com

You can have the same thing in following ways too:
*Without www
*With prefixing http://
*With prefixing http:// and removing www

So, it counts total of 12 different ways your add-on domain can be accessed through browser, resulting in the addition of great duplicacy for Google.

I was also facing the same problem and it ate my whole 1 day in order for the solution to come up. I mailed to my many blogging friends, contacted Hostgator customer support, googled but nowhere solution was coming. While googling, I got the following code at many places:

Options +FollowSymlinks
RewriteEngine OnRewriteCond %{HTTP_HOST} ^addondomain\.com [NC]
RewriteRule ^(.*) http://www.addondomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.addondomain.primarydomain\.com
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=permanent,L]
RewriteCond %{HTTP_HOST} ^addondomain.primarydomain\.com
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=permanent,L]

To place this code, go to your FTP/cpanel, primarydomain directory>>>addondomain directory>>> open .htaccess
And copy the above code in it.
But unfortunately, this code too didn’t work for me. 😉

So, if you too on the same floor, then try this:
Open your .htaccess file and paste the below code under mod_rewrite in it (by replacing addondomain with your domain).

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^(www.)?addondomain.com$ [NC]
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=301,NC,L]

This code worked for me like a charm 🙂
So, try the above 2 codes. Atleast one will definitely work for you.
Now, access your site by the above 12 different ways.
Every time, you would be redirected to http://addondomain.com

NOTE: Please do back up your .htaccess before making any changes
Replace addondomain with your respective addondomain

     
 

Author

- who has written 444 posts on TechOfWeb.

Atul is a professional blogger and techie who writes at TechOfWeb.

Subscribe to TechOfWeb feed via RSS || EMAIL || Twitter || Facebook to get instant latest tech updates.

Your Comments

18 Comments so far

  1. Nihar says:

    Great tip atul.

    Thanks.

  2. Chetan Gole says:

    Nice trick buddy, working with .htaccess file is very risky and should be done very carefully.

  3. Atul says:

    @Nihar,@Chetan,@Polprav: Thanks
    @Polprav: yes you can. If any help you can mail me.

  4. techntuts says:

    I have redirected successfully using hostgator cpanel in redirects option…

    Now i am able to redirect all the domains in a suitable way by typing with or without www

    I am able to redirect http://etuts.techntuts.org to http://etuts.org successfully…

    But main problem is i am not able to redirect http://techntuts.org/etuts.org to http://etuts.org and also

    http://techntuts.org/geekplugins.org to http://geekplugins.org

    Can anyone help me?

    • Atul says:

      @techntuts: You can try the above code that’s explained in the tutorial. It should work.

      Anyways, I don’t think it would be an issue. You can further take help from Hostgator Live technical support.
      Also, please comment here with process if you are done with it.

      • Brian says:

        OK, I tried option #2 again and now everything works except “bluewingdesign.com/wohn.org”. “www.bluewingdesign.com/wohn.org” DOES work however and so do all the other 10 ways. I’m using this code:

        Options +FollowSymlinks
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        RewriteCond %{HTTP_HOST} !^(www.)?wohn.org$ [NC]
        RewriteCond %{HTTP_HOST} !^$ [NC]
        RewriteRule ^(.*)$ http://www.wohn.org/$1 [R=301,NC,L]

        What do I add to get the non WWW to redirect? Thanks much!

      • eTuts says:

        I just took the help of the hostgator support and they were really helpful with this issue.

  5. Brian says:

    I’m having the same problem as Techntuts… ALL work except “primary.com/addon.org” (with or without the www)

    By the way, I used Option #1 – #2 did not work at all for me… Any help? Thanks!

  6. Brian says:

    OK, I tried option #1 again and now everything works except “bluewingdesign.com/wohn.org”. “www.bluewingdesign.com/wohn.org” DOES work however and so do all the other 10 ways. I’m using this code:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{HTTP_HOST} !^(www.)?wohn.org$ [NC]
    RewriteCond %{HTTP_HOST} !^$ [NC]
    RewriteRule ^(.*)$ http://www.wohn.org/$1 [R=301,NC,L]

    What do I add to get the non WWW to redirect? Thanks much!

    • Atul says:

      @Brian:
      The code worked for me. I think you need to consult your webhost in this. They will be able to help you.
      Just let us know if still you are facing the issues.

      • Brian says:

        When I put in “bluewingdesign.com/wohn.org” (without the www in front)…

        It goes here:
        http://www.wohn.org//home/bwohn/public_html/wohn.org

        With the www, it works fine. Is there another line I need, or something on CPanel I need to change. We don’t get support on a Server issue like this – any help would be appreciated. Thanks!

      • Brian says:

        Ok, no neither works? I’m confused.

        Do I need to modify the .htaccess file on the primary as well. It seems this is not getting to my secondary with: “bluewingdesign.com/wohn.org”

        • Atul says:

          @Brian: Open htaccess file of your addondomain and paste the second code in it. Please backup your htaccess file first. It should work.
          No need to add anything in primary domain htaccess.

          Also, Please let me know if you on shared hosting and also which host you are using ?

          If still you are facing issues, let us know. I will look into it then….

          • Brian says:

            Ok, I do appreciate your help!

            I did #2 again, still no luck with:
            “bluewingdesign.com/wohn.org” with or without the www.

            it returns this in the address line:
            http://www.wohn.org//home/bwohn/public_html/wohn.org
            (Internal Server Error)

            Also, a new problem that someone pointed out to me:
            “http://www.wohn.org/~bwohn” takes you to the primary server (wohn.org is the add on domain). ALL our subdomains when you add “~bwohn” it takes them to the primary domain too.

            We are using a shared virtual server on OLM using WHM and CPanel if that helps. Thanks again!

  7. Brian says:

    I tried this I found from another forum:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^bluewingdesign.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.bluewingdesign.com$
    RewriteRule ^wohn.org/?(.*)$ “http\:\/\/www\.wohn\.org\/$1” [R=301,L]
    RewriteCond %{HTTP_HOST} ^wohn.bluewingdesign.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.wohn.bluewingdesign.com$
    RewriteRule ^/?(.*)$ “http\:\/\/www\.wohn\.org\/$1” [R=301,L]

    and put it on my PRIMARY .htaccess, and put nothing in the subdomain. And now the “bluewingdesign.com/wohn.org” work, but not the “wohn.bluewingdesign.com” that worked with the code #2 here. I get part to work on one and part with the other. When I use this code here in the main and go to: “wohn.bluewingdesign.com/” it directs me to: “http://www.wohn.org/wohn.org” and of course (NOT FOUND). Hope this helps?

  8. Turk says:

    That’s a knowing answer to a dfiifcult question


Share your view

Post a comment

© 2009-2013 TechOfWeb.