Forum Moderators: phranque

Message Too Old, No Replies

MOD_REWRITE - CustomLog

         

thomasd

2:24 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



helo everyone,

I have a question about mod_rewrite and CustomLog.

I am using Mod_Rewrite to define subdomains and hostnames for users... and I also want to combine that with web servers logs... so if someone request web site: WWW.EXAMPLE.COM the user wil be redirected to /var/www/example.com/www/

and I would like to know if there is some way to write the log file to: /var/www/example.com/log

The request redirection using MOD_REWRITE is working fine, I just wanted to know it is also possible to write LOG files using MOD_REWEITE rules....

thanks...

jdMorgan

6:17 pm on Feb 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thomasd,

Welcome to WebmasterWorld!

The short answer is no.

mod_rewrite only affects accesses invoked via HTTP, so it does not affect file operations inside the server.

The usual approach to this problem is to change the logging format in httpd.conf so that the hostname (user account name) is included in the server log file. Then, a cron job is used to copy and sort the file by requested hostname, and then copy the records for each hostname into the "user" account filespace on a periodic basis. This is why many shared servers provide log files only once an hour or once a day.

The advantage of the copy and sort method is that the script doen't have to know all of the user account names. After sorting, the script simply examines each record and extracts the hostname. If it is the same as the last one processed, keep writing to the current user's log. If it is different, close that user's log, and open a new one based on the newly-found hostname. Then repeat until the end-of-file is found. You use a copy of the original server log file so that new records won't be written to it while you are trying to sort and distribute the log records.

Jim

thomasd

6:46 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



thank you Jim,

can I get script like that from somewhere? ..

I will also check stat software like analog and webalizeer, maybe I will find something... thak you

jdMorgan

7:14 pm on Feb 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> can I get script like that from somewhere? ..

Actually, I' don't know where you'd get something like that -- my post was more oriented to the 'theory' side of it than to any actual scripts.

"Stats" programs simply take the raw logs and process them into a more convenient form, so that is a functional layer above the problem you're working on now. I'd suggest you get the log-sorting problem fixed first. Then you can decide if you want to add stats at the individual user level, at the server level, or both. No need to add this complexity to the basic problem now, though.

I'd suggest a search to find what you need. The subject of "log-rotate" is loosely-related to this, so that may be a good starting point.

Jim

thomasd

7:46 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



Thanks again, I just testing webalizera, maybe I will only give web stats for some users on the server...

Thanks... have a nice day!

sun818

8:07 pm on Feb 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I always wondered how web hosts handled this!

Here's the apache docs for v1.3 for CustomLog:
[httpd.apache.org...]

This is for Apache 2.0, but the explanation is easier to understand:
[apache2docs.paradoxical.co.uk...]

The %v is used to log the name of the virtual host that is serving the request. Then a program like split-logfile [apache2docs.paradoxical.co.uk] can be used to post-process the access log in order to split it into one file per virtual host.

thomasd

11:30 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



Thank you for your post 'sun818'

I will check that...

hakre

11:13 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using Mod_Rewrite to define subdomains and hostnames for users...

i ever thought this can be easily handled with virtual hosts. isn't virtual hosts possible for you? this will save you a lot of work i think.

anyways, i think you should be able to change the logformat within the rewrite process but you can not name where to save the log. so i really think, using mod_rewrite for domain mapping might work on the file-side but not the with rest really good.

thomasd

12:54 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



hmmm, mod_rewrite will save me lot of work, coz users can create subdomains... also hostnames will be created automaticali, I don`t want to acces https.conf and generate new one, after a subdomain/or/host is created or deleted... so I will try it with mod_rewrite....

thanks for your post....

jdMorgan

4:52 pm on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Concerning "automatic" subdomain creation, see this thread: [webmasterworld.com...]

If you have a redirection loop problem on your subdomain-subdirectories, your server OS needs to support POSIX 1003.2 regular expressions in order to fix the problem. I know that FreeBSD supports them, and many versions of Unix don't, but I'm not sure about others.

Jim