Forum Moderators: phranque
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...
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
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
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.
I am using Mod_Rewrite to define subdomains and hostnames for users...
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.
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