Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointing Different Domains to Different SubDirectories 1

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
I initially posted the question in the Apache forum, here:
thread65-1602758

The jest of what I'm trying to do is control what domain (all pointing to the same IP address, same document root ( html_public folder) ultimately points to what subfolder. So technically, the document root for each domain is in a subdomain, not out in the main
What I can't seem to get correct is that I was wanting to do this in the .htaccess file, using some sort of conditional statements. I don't really care whether it's a php instruction or something else, I basically just want it to work.

Here's what I want to be able to say, but I'm clueless right now as to how to say it correctly:

Code:
If IncomingDomain = site1.com Then
  Go To /site1 subfolder
ElseIf IncomingDomain = site2.com Then
  Go To /site2 subfolder
End If

I tried doing this with the Rewrite Condition statements, but it seems to take my first condition, and run with it. If I put site1's conditions first, then everything gets changed to Site1 info.... if site2, then it's changed to site2...

What I'm guessing is that I need some sort of code in the that says:

Code:
If the incoming domain name is site1.com then
  look in folder /site1 as the doc root
ElseIf incoming domain name is site2.com then
  look in folder /site2 as the doc root
End If

Is it possible for me to use PHP or anything else to basically direct this appropriately?

If you need to see what I'm trying to do with the .htaccess file in the so far, I can post that here later. The .htaccess file in each subdirectory, currently, is the default .htaccess file set by Drupal. The one I put in the root ( http_public folder) is the one where I'm trying to direct the traffic.

Sorry if I'm making no sense, and I'd greatly appreciate any guidance on this if at all possible.

Thanks in advance. (and yes, I realize my syntax isn't right - it's basically VB/VBA syntax, so if you need me to rewrite it to make sense, I'll do so. [smile])
 
you probably could use php for this. but you'd be a loon to do so. although the best advice would be for you to change your host so that you don't have to work around this issue, the next best advice would be to use mod_rewrite.

no problems in doing this with .htaccess.

but by far the best solution is to edit your httpd.conf file to handle and recognise your virtual hosts.
 
Yeah, when I read up on this so far, the suggestions have been to use the http.conf file, but since I can't access that file, I was wanting to do it with mod_rewrite in the .htaccess file.

So, I asked if there is a way to basically say...

Code:
If Condition then
  Do stuff
Else Other Condition Then
  Do stuff
End IF

Is there a way to do that in the mod_rewrite area?

The http_conf file thing is a little annoying since I started researching this, but it seems that's the usual for shared hosting accounts, and from what I read, it makes sense for shared hosting.

Ideas on how to set up the conditions this way?
 
Following your thread here. I have been wondering whether or not you could do this in .htaccess since we were discussing it in the other thread. I did a little more digging and found this. Check out this link: I skimmed it over and it seems to be a rather thorough discussion of using .htaccess for rewrite purposes. To be honest, I intend to read it myself as it looks pretty educational.

By the way, if regular expressions look decidedly irregular to you, you might want to read up on those too.
 
Thanks a bunch! I'll take a look at that, and see if I can get it going with that.

I've used regular expressions in the past, in VBA, but it's been a while. I'll freshen up on that as well if need be.

Thanks again..
 
A quote from that site gives a little hope:
multiple domains in one root

If you are in the unfortunate position of having your sites living on a host that doesn't support multiple domains, you may be forced to roll your own with .htaccess and mod_rewrite. So long as your physical directory structure is well thought-out, this is fairly simple to achieve.

So hopefully it's "easy" once you know what you're doing. [thumbsup2]
 
Noway2,

YOU ARE MY HERO! That is an awesome link! I'm going to have to keep that one handy for sure!

Sure enough, I was able to take 3 lines per domain from that site, and plug it in, and tested with 2 domains so far, and it's the best results to date! Incredible!

I DEFINITELY want to read up more on that site, seems like the author really knows his way around the .htaccess files for sure!
 
this is bread and butter for mod_rewrite. anyone in the apache forum should be able to assist with appropriate refinements to the regex.
 
Happy to have helped. I am glad that it worked out for you.
 
jpadie,

Thanks for the mention regarding the regex. I thought the item I was trying to do should be pretty basic, but all my attempts were failing. I just had to find the right source. Of course, if I'd of thought to come to tek-tips a long time ago, I'd of found a solution much more quickly, I suppose. [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top