.htaccess FilesUpdated November 2026 for Apache 2.4. The complete, current reference is Htaccess Not Working? 500 Errors, Redirect Loops and Fixes in THE Ultimate Htaccess.
Logging and monitoring are essential for both security and performance. But start with the uncomfortable truth: a .htaccess file cannot open a log file. CustomLog, ErrorLog, LogFormat and LogLevel are server-config only. Put any of them in .htaccess and every request in that directory gets a 500 Internal Server Error. What .htaccess can do is decide what gets logged and expose useful data to you. Here is how the two halves fit together.
.htaccess Can and Cannot DoSetEnvIf that the server's CustomLog uses to include or skip requests.curl -I without any application code.This goes in httpd.conf, apache2.conf or the virtual host, not .htaccess. On shared hosting, your control panel already does it for you.
# Server config only
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined_timed
CustomLog ${APACHE_LOG_DIR}/access.log combined_timed env=!dontlog
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
%D adds the time each request took in microseconds, so slow URLs show up in the access log. env=!dontlog skips any request that has the dontlog variable set, and that variable is something your .htaccess controls:
# .htaccess: keep noise out of the access log
SetEnvIf Request_URI "\.(ico|png|jpe?g|gif|webp|avif|css|js|woff2)$" dontlog
SetEnvIf User-Agent "UptimeRobot" dontlog
To debug rewrite rules, the 2.2-era RewriteLog is gone. In 2.4 it is LogLevel alert rewrite:trace3 in the server config, and the trace lands in the error log.
Monitoring means reading those logs, and that happens outside Apache. .htaccess cannot send alerts or ban IP addresses on its own. Tools such as fail2ban, ModSecurity, a log shipper or your CDN do that, and you can then add what they find to your .htaccess block rules.
Response timing in a header: a stopwatch on every response, visible in curl -I, shown only to your own IP:
<If "-R '203.0.113.10'">
Header always set X-Served "%D %t"
</If>
Watching the logs: when a rule misbehaves, the error log tells you why.
tail -f /var/log/apache2/error.log
curl -sI https://www.example.com/some/url
Common messages: Invalid command '...' means a module is not loaded or the directive is not allowed in .htaccess. ... not allowed here means AllowOverride does not permit it. Request exceeded the limit of 10 internal redirects is a rewrite loop. The full list is in Htaccess Not Working?.
Logging is configured by whoever runs the server. .htaccess shapes what goes into those logs, exposes timing data, and enforces the blocks your monitoring tells you to add. Use each for what it can actually do, and the error log will tell you within seconds when a rule goes wrong.