junkfoodjunkie junkfoodjunkie - 4 years ago 150
Apache Configuration Question

Set PHP-log placement in .htaccess - use variable for subdomain?

Okay. I have this in my .htaccess:

# enable PHP error logging
php_flag log_errors on
php_value error_log logs/php_errors.log


Which works, but I would like for the error-log to be named according to which subdomain is active (different subdomains use the same files, hence I can't just differentiate location based on specific files being loaded).

I tried to do this (but it doesn't work):

# enable PHP error logging
php_flag log_errors on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
php_value error_log logs/php_errors_$1.log


It just returns php_errors_$1.log in the folder. So, is there a way I can assign that to a variable, and use that variable in the filename?

Answer Source

This is a little work around:

.htaccess:

php_value auto_prepend_file "/home/path/public_html/domain/setLogFile.php"

setLogFile.php:

<?php

// Get subdomain
$subdomain = array_shift((explode(".",$_SERVER['HTTP_HOST'])));

// Set log file
ini_set("log_errors", 1);
ini_set("error_log", "/home/path/public_html/domain/logs/php_errors_" . $subdomain);

?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download