0

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?

junkfoodjunkie
  • 3,168
  • 1
  • 19
  • 33
  • I believe the '$1' is only accessible from a 'RewriteRule'... – Andrew Mast Feb 04 '17 at 17:51
  • Yeah, I figured... so I was just wondering if there is some other way to write something similar. – junkfoodjunkie Feb 04 '17 at 17:53
  • I think it would be best if you created a .htaccess file in each subdomain and set the error_log with that – Andrew Mast Feb 04 '17 at 17:55
  • Found a little work around. Posted it as an answer since it was too long – Andrew Mast Feb 04 '17 at 18:02
  • There is no separate subdomains per se. Just different subdomains which all goes to the same folder, PHP picks up different config-files, wihch decides which DB to load and such, but there are no place to put the different .htaccess-files. – junkfoodjunkie Feb 04 '17 at 18:04
  • You could try doing something like this in the apache configuration rather than .htaccess. http://stackoverflow.com/questions/20217533/dynamic-apache-log-directory-based-on-hostname – tjfo Feb 04 '17 at 19:16
  • Not really an option, since this app is downloadable, and the solution will need to be available even if editing configuration files is not possible. – junkfoodjunkie Feb 04 '17 at 19:26

1 Answers1

1

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

?>
Andrew Mast
  • 311
  • 1
  • 17
  • This works, but sort of defies the point of trying to use .htaccess for the setting, instead of using PHP... I will consider doing this if there is no other solution for it, though. – junkfoodjunkie Feb 04 '17 at 18:06
  • Okay. I don't think that there is a way of doing it via the .htaccess if you have all the sub-domains in the same directory. – Andrew Mast Feb 04 '17 at 18:07
  • I've set this as the answer, since it works fine, and doesn't do much to make it more complicated. Thanks for the tip! – junkfoodjunkie Feb 05 '17 at 01:41