Netlify redirects

Those running a public web server are frequently subject to bot scans. While using best practices is the proper approach, there may still be a lot of 404 log results from bots. One choice is to ignore these results in the 404 log.

Another choice is to return HTTP status codes. However, Netlify only allows a few _redirects HTTP status codes so it can’t make 5xx HTTP return codes. We decided to simply redirect bots to /bot.html, an empty file.

Empty files

Since these files are legitimate, but may not be used by your site, we create empty files for these:


_redirects file

The Netlify _redirects file should usually NOT be at the root of the source repo, but should instead be in the site publish directory. For Hugo it may be public/_redirects. We prefer the _redirects file to netlify.toml, because the redirect syntax is much more concise in _redirects files.

Append to _redirects file as below. Use Netlify Playground to instantly test file syntax.

/.env /bot.html
/ /bot.html
/.git/HEAD /bot.html
/.git/index /bot.html
/posts/.git/config /bot.html

/apple-touch-icon-precomposed.png /favicon.ico
/apple-touch-icon-152x152-precomposed.png /favicon.ico
/apple-touch-icon-152x152.png /favicon.ico
/apple-touch-icon-120x120-precomposed.png /favicon.ico
/apple-touch-icon.png /favicon.ico
/apple-touch-icon-120x120.png /favicon.ico
/assets/img/favicon-32x32.png /favicon.ico

/assets/images/scivision-logo.png /favicon.ico
/assets/images/scivision-avatar.png /favicon.ico
/assets/images/header.jpg /favicon.ico

/wp-login.php /bot.html
/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php /bot.html
/xmlrpc.php /bot.html
/config.bak.php /bot.html

/wp/* /bot.html
/wp1/* /bot.html
/wp2/* /bot.html
/wordpress/* /bot.html
/2018/* /bot.html
/2019/* /bot.html
/2020/* /bot.html
/cms/* /bot.html
/media/* /bot.html
/news/* /bot.html
/shop/* /bot.html
/sito/* /bot.html
/site/* /bot.html
/test/* /bot.html
/wp-includes/* /bot.html
/web/* /bot.html
/website/* /bot.html
/wp-content/* /bot.html