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

时间:2017-02-04 17:48:09

标签: php apache .htaccess

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?

1 个答案:

答案 0 :(得分:1)

这是一个小问题:

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);

?>