Apache 2.4 Rewrite 404 errors log

debian logoapache Logo

- Create 1 conf file in apacheย :

$ nano /etc/apache2/conf-available/rewrite-log-404.conf

- Paste this code inside /etc/apache2/conf-available/rewrite-log-404.conf


RewriteEngine On
# exclude directory index
RewriteCond %{REQUEST_URI} !/index\.(php|html?)$
# exlcude auto-index of directories
RewriteCond %{REQUEST_URI} !/$
# if the request is not a file, directory, or symlink
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# set the "notfound" environment variable
RewriteRule ^ - [E=notfound:true,L]

# LogFormat  Vhost log
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %X" vhost_combined
 
 
CustomLog /var/log/apache2/error.log vhost_combined env=notfound
CustomLog /var/log/apache2/requests.log vhost_combined env=!notfound

- Activate conf with:

$  a2enconf rewrite-log-404

-------------------------------
by ๐Ÿ…ด๐Ÿ†๐Ÿ†๐Ÿ…ด๐Ÿ†„๐Ÿ†32

Hosted on
๐Ÿ…ด๐Ÿ…ฒ๐Ÿ…ท๐Ÿ”ต๐Ÿ†‚๐Ÿ†ˆ๐Ÿ†‚๐Ÿ†ƒ๐Ÿ…ด๐Ÿ…ผ