Forum Moderators: phranque
We have a client that is about to expand areas, and need to add URLs like:
nashville.domainname.com
atlanta.domainname.com
houston.domainname.com
*.domainname.com
Then I need to be able to reference that subdomain name as a variable in all the PHP scripts on the site.
So, nashville.domainname.com would serve www.domainname.com/index.php?nashville
However, I'm also thinking that might cause a problem with any scripts that already have query string URLs.
Like:
www.domainname.com/showUsers.php?startID=12345
would then need to be
nashville.domainname.com/showUsers.php?startID=12345
and that would serve
www.domainname.com/showUsers.php?startID=12345&city=nashville
Thanks for any help y'all can offer!
# check to see that there is a host (HTTP 1.0 clients do not send one, and will not end up at the right place if we don't exclude them.)
RewriteCond %{HTTP_HOST} .
# check to make sure the site is not www or the non-www version.
RewriteCond %{HTTP_HOST}!^(www\.)?yoursite\.com
# store anything upto the dot in a variable
RewriteCond %{HTTP_HOST} ^([^.]+)\.yoursite\.com
# use the greedy .* so if we have qualified for all the other conditions, we don't fail here because there may not be a query string.
RewriteCond %{QUERY_STRING} ^(.*)
# check any request... if you do not need to store the original URL or request in the string, you can use the much more efficient .(dot) without the () or the '+' EG RewriteRule . /yourfile.php?variable=%2&%3
RewriteRule (.+) /yourfile.php?variable=%2&%3 [L]
I do not remember off the top of my head if you can 'back reference' 2 separate conditions, so we may need to find a way to combine the conditions so we can reference both the query string and the host from the same condition, then pass the variables, or separate out the rules EG one for query string requests and one for non-query string requests... it's not something I use too often, but I will try to find some more information over the next couple of days, or maybe if Jim or someone more used to this situation, pops in they could give you a more solid direction...
Hope this gives you some ideas.
Justin