With Apache’s mod_rewrite rule, php error logging becomes extremely easy. The rules are simple but yet powerful. This enables you to log all errors generated during PHP runtime. It makes debugging a pleasure thing to do while it also hide the errors from showing on your live website.


Error Logging With Apache Mod_rewrite Rules:




Before writing the rules, we need the htaccess file on the root of your website.

Creating a htaccess file on any Windows server may need a little trick since the normal right-click->create file would not work.

  • In Windows, just simply open notepad and then save as “.htaccess”(without quotation mark), then you have an empty htaccess file to work with.



Add the following rules to the htaccess file.

#Beginning of suppress rules
#The following rules suppress PHP errors
#These rules are ideal for using on live website,
#However, you may not want to suppress any errors on your development site.
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
#End of suppress rules

#Beginning of logging rules
php_flag  log_errors on
php_value error_log  /path/to/errors.log
#End of logging rules



Note: The directory which will contain your errors log file must exist before any errors are logged, otherwise it will not create the log file automatically.