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!

.htaccess Conditional Statements 1

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
Hi, I've done a quick brief over some of the FAQs, and searching some forum postings, so please redirect me if I missed one that is accurate to my question.

First, I just want to make sure I've got it down pat - so, is Apache using PHP programming, or else is it basically it's own language in the configuration files, or what? Well, that's just an aside, trying to understand things better.

Here's my situation that I'm trying to sort out currently:

1. I've got a shared hosting account, where I've put up 2 totally separate installed drupal websites - the databases (mysql) are totally separate, and the code base is totally separate.

2. The way I have it configured is I installed each their own mysql database, and put the drupal files for each site in it's own subdirector under the server folder. So, they are like this: points to and points to
At least that's how I WANT it to work.

One of the domains is handled by the web host, and the other domains (all pointing to site2) are registered via another provider.

From what I've seen, it looks like the best performance will be in configuring my .htaccess file(s) correctly to get the job done.

So, here's what I'm trying to do:
1. For each domain, I would like to put a conditional statement of some sort - an IF statement, or even CASE statement if one exists for .htaccess files....

Instead of talking more, I'm goign to type up what I'd like to do, though I have NO CLUE if this is even close to possible:

Code:
<If Incoming URL = [URL unfurl="true"]www.site1.com[/URL] Then
  Do all the stuff for this domain/directory
>

<If Incoming URL = [URL unfurl="true"]www.site2.com[/URL] Then
  Do all the stuff for this domain/directory
>

From what I've seen, I'm sure that's not correct syntax, but I'm just trying to get the idea accross.

What I've tried to do is using the REWRITE directives, if that's the correct terminology.

I tried having REWRITECOND .... dealing with site1
REWRITERULE.... dealing with site1
REWRITECOND.... dealing with site2
REWRITERULE.... dealing with site2

But what ends up happening is it follows the first one, and ignores the second.

Is there not a way to have the code follow a certain section if the correct domain was entered, or else follow a totally separate section of code if the second domain is entered?

Please forgive my ramblings. I want to learn a lot in this area, and think I have the capacity to. I just have so many irons in the fire, that I tend to run out of time for learning such.

Any references, suggestions, etc greatly appreciated.
 
To answer your first question, Apache is the web server application. It is what responds to the requests from the browser. In response to the requests, it serves up web pages. The pages can be designed in several ways, with the simplest being plain HTML. PHP is a language that is used to provide a function called server side scripting. It is code that is interpreted and executed on the server platform. To use it with Apache, you need to install PHP as a separate application. Chances are it has already been installed for you.

For your second question, it looks like you have things setup correctly. Each host (website) is located in its own directory, which is good. Apache supports what are called virtual hosts. This means that you can even have multiple, different websites on the same server / same IP. The easiest way to set these up is in the location where you declare your hosts. It sounds like your setup has different IP addresses for each site. In this case you tell apache to assign one site to one IP and the other to the other IP. The declaration will look something like this: <virtual host ip.addr.num.1:80>.

 
Thanks for the info, Noway2.

As for the IP, it's a shared hosting setup, all using the same IP address.

Although I'm able to get to most everything under my shared hosting package, I don't think I can access the http_conf file which is where I think the declaration you're referring to would go... or can I put that in .htaccess or php.ini possibly.

So, can I just plug <virtual host....> into the .htaccess file, or do I need a separate file for that?

Also, the sites are separate Drupal sites, and I've got some Mod rewrite rules in there that worked great when I just had one site in one subdirectory. The problem came in when I introduced another. If I don't use redirects, but rather just point them to the root and allow the .htaccess file to take over, then it sends them all the same way.

So, getting back to the first question about Apache... Is it possible to use HTML, PHP and/or others all in the same file, or does it require a certain language?

Thanks again, and sorry for rambling...

My main, #1, concern is just to be able to send each domain to the directory that I have set up for it.

If at all possible, I'll look at putting in the <virtual host...> lines in the .htaccess file this evening (the one in the root)... and then I guess any other rewrite type rules should be placed in the .htaccess file within each subdirectory - for each site.

I'll post back with my progress, regardless in this ever learning process. [smarty]
 
I really don't know what the restriction are for where you can and can not put your vhost directive. You mentioned Drupal, which typically uses an alias directive to link to a location outside of the document root.

As far as PHP and HTML, you can combine two in one file. The PHP sections will be tagged and lie between <?php and ?> directives. For example:
Code:
<html>
  <head>
    <title>Sample</title>
  </head>

  <body>
     <p>This is plain html</p>  
     <?php
        $string = "This is php<br/>";
        print "$string";
     ?>
   </body>
</html>
I would suggest checking out the PHP forum here. It has very active participation.



 
Thanks, I'll pop over to that forum as well. Funny, as long as I've been a member of tek-tips, I've never thought about using it for much info on the Drupal web php-type stuff. [ponder]
 
The new thread in the php forum, for reference:
thread434-1602845
 
I just HAD to give another start to NoWay2 for the link he found and posted in the other referenced thread (php forum). The linked page is a VERY VERY useful page for understanding, and making use of the .htaccess files... well, at least it seems that way to me so far!

Thanks again, Noway2! [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top