Forum Moderators: phranque

Message Too Old, No Replies

Redirect multiple domains to page with different query string param

         

Quimbly

5:46 pm on Jan 12, 2011 (gmt 0)

10+ Year Member



Hi all,

I'm currently hosting multiple domains on a single web space. The files for each website are located in different folders:

 domain1.com in /public_html/folder1
domain2.com in /public_html/folder2
domain3.com in /public_html/folder3


Currently the redirects are handled by some behind-the-scenes mechanism, which I can't discern. It's managed through the cPanel as add-on domains.

All of the sites are the same, with the exception of some personal data, some photos, and some links. So, I wrote some php code to swap out these details, based on an ID from the query string. Everything is ready, but now I'm looking for a way to use my .htaccess to redirect requests for each of the domain names to the *same* folder and file, but with a different query string parameter.

E.g.
domain1.com -> /public_html/folder4/index.php?id=1
domain2.com -> /public_html/folder4/index.php?id=2
domain2.com -> /public_html/folder4/index.php?id=2


Also, obviously, the domain names needs to be preserved:

 domain1.com -> domain1.com/index.php?id=1
domain2.com -> domain2.com/index.php?id=2
domain3.com -> domain3.com/index.php?id=3



I'm a novice with .htaccess, and so am having one heck of a time getting this working.

Can some kind soul out there help me out with this one?

Thanks!

jdMorgan

5:31 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Currently the redirects are handled by some behind-the-scenes mechanism, which I can't discern. It's managed through the cPanel as add-on domains.

Technically, these should be internal rewrites, not external redirects.

If you've used cPanel to generate the config code to rewrite (map) domains to subdirectories, then the first step is to go see if you can change that mapping. If so, then point them all to the same (sub)directory as a first step, and then we can discuss the (trivial) additional .htaccess code.

If not, then this hosting account cannot support the approach you're trying to use, because the cPanel domain-to-subdirectory mapping will occur before your .htaccess file ever gets a chance to run.

To overcome this, you *could* put .htaccess files in each domain-subdirectory, containing code to redirect domain2 and domain3 back to domain1 with a query string, but this would have the effect of exposing your query string and exposing the fact that these are all now the same domain. This would likely cause some major disruption to your search engine rankings... including the total disappearance of domain2 and domain3 from search listings. All of your URLs would then show as being hosted on domain1. Therefore, I would strongly recommend seeking out more-suitable hosting in this case. IP-based shared hosting (also referred to as having a unique/non-shared IP address) can easily be used for this. The cost adder is typically $1 per month in the U.S., although this can vary from more-expensive to unavailable in other countries.

Jim

Quimbly

7:06 pm on Jan 17, 2011 (gmt 0)

10+ Year Member



Thanks so much for the info, Jim. These are the kind of details I was needing! Much appreciated.

As it turns out, I believe, all I will need to use is domain parking. I'll use one domain as the base, and then park the other domains on top of it, rather than use add-on domains and .htaccess hacks. If I'm right, this will do what I need: serve the same content, from the same folder, for different domains, yet still preserve the typed-in URL. If this is the case, I can simply change my PHP code to inspect the typed-in domain name to determine the personalized content to get from the DB.

Do you see any problems with that approach?

Thanks again!

jdMorgan

10:29 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As "parking" is a non-technically-precise term, I can't say. The part about using PHP to inspect the requested hostname is fine, but you're still at risk of problems related to precisely how the server is configured to handle these additional hostnames.

Jim