Pass hidden variable through based on domain name

Using a single web hosting account to host multiple sites

Pass hidden variable through based on domain name

Postby ludlow » Wed Jul 29, 2009 1:21 am

I've been working on a relatively complex multi-city project, and one of the things we're trying to do is to pass identifying variables through based upon domains.

I've managed to make this work just with a domain by doing the following:

Code: Select all
  rewriteRule ^boston/(.*)$ $1?%{QUERY_STRING}&NID=5 [L]


So in this case, if you go to our http://www.domain.com/boston/file.php

This would be the same as going to http://www.domain.com/file.php, but with the hidden variable NID automatically passed through and set to 5.

What I am now trying to do is to find a way to interpret custom domains. So using the above, assume I had the following:

http://www.bostoncity.com/
http://www.houstoncity.com/
http://www.abcdcity.com/

Each one of those should point to the same location on our server (www.domain.com using my first example), only I need each one of them to pass that same NID variable through as a hidden variable.

Ultimately as the user browses the site, they will remain on one of these URLs, only I'll know what one specifically based on the NID variable.

Any thoughts would be greatly appreciated!

I guess the short is that I need, say 100 domain names to point to the same directory on my server (which is easy to do), only I need the local .htaccess file to read the domain name and pass a variable with it.
ludlow
 
Posts: 2
Joined: Wed Jul 29, 2009 1:11 am

Postby ludlow » Wed Jul 29, 2009 10:43 am

After a night of searching, I did find my solution:

Code: Select all
RewriteCond %{HTTP_HOST} domain1.com [NC]
RewriteRule ^(.*)$ $1?NID=1 [QSA]

RewriteCond %{HTTP_HOST} domain2.com [NC]
RewriteRule ^(.*)$ $1?NID=2 [QSA]


That will let both domain1.com and domain2.com function normally, only the NID variable will be appended to the Request String (unbeknown to the end-user).
ludlow
 
Posts: 2
Joined: Wed Jul 29, 2009 1:11 am

Postby richardk » Wed Jul 29, 2009 3:49 pm

You should add the L flag to stop processing of further rules when the rule matches.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 2 guests

cron