Support » Plugin: Cleverwise Redirect It » Redirecting sub-domains to the main home page

  • Resolved anatolyv


    Hi, I have several sub-domains that I need to redirect to the main home page of my site. Examples:
    – should open
    – should open
    I need to do this so that JavaScript on the main home page can detect ‘john’ or ‘kate’ in the URL of the sub-domain and customize the main page for either John or Kate. This way I will have one site that will look different for different owners of my sub-domains.

    I created sub-domains with my hosting provider and pointed them to a separate sub-directories under public_html. I do not know how to redirect them to the main page. Forwarding them at the hosting provider level won’t work because it will be forwarded before the page opens and I won’t be able to read the sub-domain with JavaScript. Can you help me with this? Thank you!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Jeremy O'Connell


    While I don’t know your hosting setup I am guessing it is shared hosting (over Cloud, VPS, dedicated), and your host is using the Apache web server.

    If all this is true then directing back to the main domain is quite easy using a .htaccess file.

    So in the subdomain directory add the following information into a .htaccess file and upload it to the directory.

    RewriteEngine on
    RewriteRule ^(.*)$ [R=301,L]

    Now it is up to you to decide on what variable name you wish to use, but it shouldn’t clash with any in use by other systems like WordPress. Now it is just a matter of having Javascript look for the variable of tpl and if it matches kate insert kate’s information.

    The same holds true for John. So in the subdomain directory add the following information into a .htaccess file and upload it to the directory.

    RewriteEngine on
    RewriteRule ^(.*)$ [R=301,L]

    However keep in mind once a user clicks another page this information won’t stay. If you want the kate, john, etc information to stay you’ll need to either to set that in the user’s cookie or in a session.

    There are other ways to accomplish this but that is probably the easiest. However for additional information another way would be to redirect to a pass through script on the main domain that would set a cookie or session variable then redirect to the main domain. This could remove the ?tpl=john in the above example and still have a variable set. This method would involve having a small script programmed.

    Wow! Thank you so much for such a detailed response. I will try and will let you know.

    Jeremy, thank you! Your suggestion works! Gave you 5 stars! Two follow-up questions:

    1. How can John or Kate send a link to a specific page on the site using their sub-domain (e.g. One way is to add a link to every single page in the .htaccess, which is too laborious to maintain. Is there another way? It would be ideal to always display the sub-domain in the URL as you browse the site.
    2. I am unable to register the sub-domain with search engines because it is redirected to the main site. I need it because a lot of people enter URLs in the search field of the search engines’ home pages (NOT in the URL field of the browser). In this case, the sub-domain is not found at all.

    If this is outside the scope, no worries. Many thanks in advance.

    Plugin Author Jeremy O'Connell


    1. I would personally use a script to set a cookie or session variable and then redirect to the main site. Otherwise you are looking at some more advanced set ups.

    2. This is going to be an issue because WordPress writes the URLs. A plugin might way work but out of the box the URLs will overwritten with the main domain unless you go with the multiple setup.

    Thank you. Can you elaborate on #2? Would your plugin work? I actually have multi-site installed, but I am not using it for now.

    Also, would your suggestion in #1 with a sessioin variable resolve the issue in #2?

    Plugin Author Jeremy O'Connell


    Well keep in mind Google has a duplicate content “penalty”. So if you want to create two, three, four, twenty, etc sites all the same with only token differences like a contact name Google will see the other setups as copies. Or duplicate content.

    Now there is great debate when content is no longer duplicate in otherwords how much has to be changed but simply creating the same site over and over and over with a different subdomain isn’t going to help your SE ratings.

    I am not sure of your end game here. If you simply want agents then a cookie or session can tag a visitor. A cookie is easier though as you don’t have to maintain anything on the server. There is also frame technology but that generally isn’t to well regarded for standard sites.

    Are you going to sell off this site? Do e-commerce? That changes things , if so, because then you can get into SSL certificates which is another layer.

    You are hitting limits of WordPress. My plugin won’t solve this issue of having the subdomain stay at the top (or in the links). To do this you would really need your own server (or VPS or Cloud) and point all subdomains to your hosting IP then have a plugin rewrite the WP URLs on the page.

    That is probably doable, although I have never research it as I have never needed too. Still it won’t do much for you for Google because of the duplicate content. Google doesn’t want to display fifteen pages that are the same with only minor name changes or something. Nope.

    If I was going to log agents I would just pass all subdomains through a script to set the cookie and then redirect to a page on the site. A script could be setup to redirect to ANY page on the master site. I am available for hire if you want that solution as that is beyond the scope of this plugin.

    Still Google duplicate content and take a look. For search engines a bunch of separate sites won’t help. If you want your agents (or whatever) to be happy that is a different story.

    Hi Jeremy, You are absolutely correct, I do not want duplicate pages. To answer your question, my goal is to provide the affiliate marketing program for

    I created sub-domains for distributors that open my website. When a client uses a sub-domain, e.g. kate.powerofaloe, JavaScript records ‘kate’ in a cookie. When client clicks on ‘Buy’, JavaScript reads ‘kate’ from the cookie and passes Kate’s ID to the online store. Kate gets commission and I get commission on the sale.

    Your initial solution of 301 redirect in .htaccess works except that kate.powerofaloe is not found when entered in Search field of the browser (not the address bar). Search engines’ bots index pages after the 301 redirect, not before.

    Can I create a landing page kate.powerofaloe and then redirect to the main site? How would search engines treat such landing page? All I need is this page to appear in search result when an EXACT sub-domain string is searched for. I can do it using WordPress multi-site…

    If you have a solution that would solve my problem, I would be happy to use your services.

    Plugin Author Jeremy O'Connell


    I visited your site and I noticed the shopping experience is sent to another domain – Is that a domain under your control or a third party?

    Also what are your plans for PoA? Do you want lots of affiliates/agents or only a select few? is not under my control, but I am passing an individual ID to that site, which depends on the sub-domain used. If you open my site as kate.powerofaloe, then Kate’s ID will be passed to foreverliving (and you will see her name in the online store). If you open my site as lucy.powerofaloe, then Lucy’s ID will be passed. I expect to have at least a few dozens of affiliates/agents.

    Plugin Author Jeremy O'Connell


    I understand.

    What I would do is create a script that can set a cookie and forward a visitor to any page on the main site. I would place this on the main site. Then using the .htaccess files redirect all traffic from subdomains to this redirect and cookie file.

    Now a visitor is tagged with that agent and the agent can send any visitor to any page by simply taking the main URL and adding their agent name/code at the front.

    The final step involves sending all redirects to the ecommerce site through another script to grab the cookie information and send it to remote server.

    Some work to step up however it all flows nicely and allows for some flexibility.

    Ok, this will solve the link to every page issue, which is a nice to have. Do you see how to fix the main problem of finding sub-domains when entering them in the search field of the browser?

    Plugin Author Jeremy O'Connell


    “finding sub-domains when entering them in the search field”?

    I don’t follow your question. The above example solves setting the cookie to tag the visitor and linking to any page on the main site.

    The above example won’t keep the subdomain in the URL if that is what you mean but once a visitor is tagged is that really a big deal? The point is for the agent to get credit for the visitor and that is occurring. Of course no system is 100% foolproof and visitors will slip through the cracks but that is just the cost of doing business as an affiliate.

    Tagging the visitor is already implemented. I am sorry if I was not clear on this. If you log in as kate or lucy, you will see their names on the site and we pass their IDs to

    My initial question to you was on redirecting from sub-domain to the main site, which you easily resolved. But now my biggest problem is the fact that many users do not know the difference between the search field and the address bar of the browser. If they enter the URL in the search field they will never find the site because of the 301 redirect. I’ve seen many people do this and this is a sizeable share of the users that I cannot ignore…

    Plugin Author Jeremy O'Connell



    Yeah I have seen users do this too. Crazy isn’t it?

    Well then your option is don’t 301 code the URL. Instead do a 302 or 200. Again I would do a script because you could redirect ANY URL at say and it would always tag, redirect to main site page, and should display in the SE’s if a user types it in (at least eventually).

    Another option is offer a bonus download (like ten ways to better use aloe or something) and people have to type a code (kate, john, etc) to download it; just a thought.

    I was reading about 302 and understand that it’s bad for SEO. I also do not understand how is it functionally different from 301 as it relates to my question. My main goal is the following: enter in the SEARCH field of Google, Bing or Yahoo and see a link in the search result. Same should work for lucy, anatoly, and dozens of other sub-domains I create. Is this doable? I do not quite understand the 200 redirect…

    Entering a code is certainly possible, although customer experience won’t be as smooth…

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Redirecting sub-domains to the main home page’ is closed to new replies.