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

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动