LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 10-05-2006, 03:48 AM   #1
NaX
LQ Newbie
 
Registered: Feb 2005
Location: South Africa
Distribution: FreeBSD/PCBSD
Posts: 17

Rep: Reputation: 0
apache: mod_rewrite in mass vhost setup


Hi

I have setup a mass vhost on our Fedora server for subdomains, where the DocumentRoot is dynamically changed.

First attempt I used RewriteEngine, and I got it to work the seconds try I used VirtualDocumentRoot and I got it working.

The problem comes in when I tried to uses clean urls in one of the subdomains using the RewriteEngine in my .htaccess.


.htaccess

Code:
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite URLs: 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
--------------------

Vhost first try.

Code:
<VirtualHost *:80>
....

     RewriteEngine on
     RewriteCond   %{HTTP_HOST}                 [^.]+\.domain\.com$
     RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
     RewriteRule   ([^.]+)\.domain\.com(.*)      /path/to/site/$1$2

...
</VirtualHost>
--------------------

Vhost second try.

Code:
<VirtualHost *:80>
....

VirtualDocumentRoot /path/to/site/%1

...
</VirtualHost>
With both vhost setups everything works fine until I put the .htaccess file up on one of the subdomains.

Here is some of the Errors got.
A)
[Thu Oct 05 09:32:51 2006] [error] [client 196.2.124.252] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary., referer: ...
B)
[Thu Oct 05 09:31:12 2006] [error] [client 196.2.124.252] Request exceeded the limit of 15 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: ...

Error A I got first so I put RewriteOptions MaxRedirects=15 into my vhost (I also tried it in my .htaccess). Then I got error B. So I put LimitInternalRecursion 15 in my vhost. Then I got error A again so I increased the value then I got error B again, and so it continued.

If I create a separate vhost for that one subdomain I want to use clean urls it all works fine.

I am don't know what the problem is. Everything works fine by itself, but when I mix things it seem to go wrong.

Can anybody help me.

Thanks.
 
Old 10-12-2006, 03:45 AM   #2
NaX
LQ Newbie
 
Registered: Feb 2005
Location: South Africa
Distribution: FreeBSD/PCBSD
Posts: 17

Original Poster
Rep: Reputation: 0
:confused:

This really frustrating me now. I am so close to reaching my goal.
My goal is to setting up apache in such a way that I don't need to restart apache when adding vhosts.

I have found a way to do sud domains and now I have found a way to do domains. I have not test the 2 together and make them play nice. I have also found a way to create access logs using piped php file so that I can still using things like webalizer.

The only thing stopping me is when I use RewriteEngine in my .htaccess. Because I use drupal a lot I am testing using drupal's .htaccess.

In my test I create dns record for *.hello.com and then created a directory hello.

Here is my VirtualHosts for domains.

Code:
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.*.com
    Options Indexes FollowSymLinks MultiViews ExecCGI Includes
    VirtualDocumentRoot /home/httpd/html/%2
    LimitInternalRecursion 20
    CustomLog "|/etc/httpd/createlog.php" "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.com
    Options Indexes FollowSymLinks MultiViews ExecCGI Includes
    VirtualDocumentRoot /home/httpd/html/%1
    RewriteOptions MaxRedirects=20
    LimitInternalRecursion 20
    CustomLog "|/etc/httpd/createlog.php" "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
</VirtualHost>
My php logging script.

Code:
#!/usr/bin/php
<?php

set_time_limit(0);

declare(ticks=5);
pcntl_signal(SIGTERM,"handle_signal");
pcntl_signal(SIGHUP, "handle_signal");
pcntl_signal(SIGINT, "handle_signal");

/* Define STDIN if not already done so */
if(!defined("STDIN")) {
    define("STDIN", fopen('php://stdin','r'));
}

while (TRUE) {
  $line = fread(STDIN, 1024); // Read up to 1024 characters or a newline
  if ($line) {

    $pos = strpos ($line, ' ');
    $host = trim(substr($line, 0 , $pos));
    $log = trim(substr($line, $pos));

    $log .= "\n";

    $logpath = '/home/httpd/weblogs/';

    $log_file = $logpath . $host . '_access_log';

    $handle = fopen($log_file, 'a');
    fwrite($handle, $log);
    fclose($handle);

  }
}

exit(0);

function handle_signal($signo) {
  switch ($signo) {
    case SIGINT:
    case SIGTERM:
      exit(0);
      break;
  }
}

?>
This all works fine. The only problem is when I use my .htaccess.

Here is my backtrace

Code:
[Thu Oct 12 10:09:44 2006] [error] [client 192.168.0.202] Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Thu Oct 12 10:09:44 2006] [debug] core.c(3009): [client 192.168.0.202] r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /node/1
[Thu Oct 12 10:09:44 2006] [error] [client 192.168.0.202] Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3009): [client 192.168.0.202] r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /home/httpd/html/hello/index.php, referer: http://hello.com/node/1
[Thu Oct 12 10:09:44 2006] [debug] core.c(3015): [client 192.168.0.202] redirected from r->uri = /favicon.ico, referer: http://hello.com/node/1
Does any body have any ideas, or am I trying something that is never going to work. I am using Apache 2.2.2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you setup a vhost Master Fox Slackware 0 01-25-2006 02:47 PM
How to setup a vhost? runeleader Linux - Networking 5 11-15-2005 11:35 AM
Apache: Alias is working on ssl vhost but not on mass vhost jonavogt Linux - Software 0 06-07-2005 02:05 PM
vhost in apache jelgavchik Linux - Networking 3 02-07-2005 06:41 PM
apache 1.3 vhost z4Rilla Linux - Software 0 08-03-2003 06:44 AM


All times are GMT -5. The time now is 08:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration