douke7431 2017-02-04 17:48
浏览 67
已采纳

在.htaccess中设置PHP-log位置 - 将子变量用于子域?

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条回答 默认 最新

  • duanjie2701 2017-02-04 18:02
    关注

    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);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题