Files bots look for on a WordPress site, and the server rules that close them

Nine server rules for the files a WordPress site should never give out

Most WordPress sites I have worked on, or still work on, usually have a few files in them that nobody meant to publish: a .git folder from a deploy, a database dump from a migration, a debug.log that has been growing for two years, a composer.lock that lists every library with its exact version. None of them shows up on the site itself, so nobody looks. Bots look, because these names are the first thing they ask for.

In 12 security gaps you can spot with a browser and curl I showed how to find them from the outside. This post is the other half: the server rules that close each one, for Apache (.htaccess) and Nginx, how to test them and what each rule may break.

Problem: The web server hands out every file it finds in the site folder unless something tells it not to. WordPress only protects itself through PHP, and these files never reach PHP: /.env, /backup.zip or /wp-content/debug.log are sent straight from the disk to whoever asks.

Solution: Answer such requests with 404 at the server level, before WordPress starts. The rules below go from the biggest risk down to the cheap ones. Put the Apache rules at the top of the .htaccess file in the site root, above the # BEGIN WordPress block. Put the Nginx rules into the server block, above the location ~ \.php$ block. After each rule, run the check that goes with it.

I use 404 and not 403 on purpose: 403 says “this file exists, you just can’t have it”, 404 says nothing.

The paths below use the default wp-content. If your site uses another folder name, change it in the rules.

1. Hidden files: .git, .env and everything that starts with a dot

A .git folder in the web root holds the whole history of the code, often with old passwords that were committed once and removed later. Tools that rebuild a repository from /.git/ over plain HTTP are free and take minutes. A .env file holds database passwords and API keys in plain text. Both appear when a site is deployed with Git or copied from a developer’s computer, and both are invisible in the browser.

Check:

$ for p in /.git/config /.git/HEAD /.env /.htpasswd /.DS_Store; do curl -s -o /dev/null -w "%{http_code} $p\n" https://example.com$p; done
200 /.git/config
200 /.git/HEAD
404 /.env
403 /.htpasswd
404 /.DS_Store

Any 200 here is a real leak. The rule closes every file and folder whose name starts with a dot, but leaves /.well-known/ open, because SSL certificates (Let’s Encrypt) and app links are checked there:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (^|/)\.(?!well-known(/|$)) - [R=404,L]
</IfModule>
location ~ /\.(?!well-known(/|$)) { return 404; }

What may break: nothing on a normal site. If the folder was deployed with Git, the deploy keeps working: Git reads .git from the disk, not over the web.

2. Backups, database dumps and wp-config copies

This is the one that hurts most. After a migration people leave backup.zip, site.tar.gz or dump.sql in the web root. Editors leave wp-config.php.bak, wp-config.php~ or wp-config.old. Migration plugins leave archives in their own folders. One of these files is the whole site with its database and passwords, and the names are easy to guess:

$ for f in backup.zip site.tar.gz dump.sql wp-config.php.bak wp-config.old wp-config.txt installer.php; do curl -s -o /dev/null -w "%{http_code} /$f\n" https://example.com/$f; done
404 /backup.zip
404 /site.tar.gz
200 /dump.sql
200 /wp-config.php.bak
404 /wp-config.old
404 /wp-config.txt
200 /installer.php

A copy of wp-config.php with any other ending is served as text, so the password is right there:

$ curl -s https://example.com/wp-config.php.bak | grep DB_PASSWORD
define( 'DB_PASSWORD', 'S3cret-example-only' );

installer.php is the leftover of a Duplicator migration. It should be deleted when the migration ends, and older Duplicator versions had a known hole that let anyone who opened a forgotten installer run their own code on the server.

The rules close every file whose name starts with wp-config (WordPress reads wp-config.php from the disk, it never needs it over the web), dump and backup endings, files ending with ~, archives in the site root and in wp-content, the Duplicator installer and the backup folders of UpdraftPlus, All-in-One WP Migration, Duplicator and BackWPup:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (^|/)wp-config[^/]*$ - [NC,R=404,L]
RewriteRule \.(sql|sql\.gz|sql\.zip|sqlite|sqlite3|db|bak|old|orig|save|wpress)$ - [NC,R=404,L]
RewriteRule ~$ - [R=404,L]
RewriteRule ^(wp-content/)?[^/]+\.(zip|tar|tar\.gz|tgz|gz|7z|rar)$ - [NC,R=404,L]
RewriteRule ^(installer|installer-backup)\.php$ - [NC,R=404,L]
RewriteRule ^wp-content/(updraft|ai1wm-backups|backups-dup-lite|backups-dup-pro|backup-db|backupwordpress[^/]*|uploads/backwpup[^/]*)(/|$) - [NC,R=404,L]
</IfModule>
location ~* /wp-config[^/]*$ { return 404; }
location ~* \.(sql|sql\.gz|sql\.zip|sqlite|sqlite3|db|bak|old|orig|save|wpress)$ { return 404; }
location ~ ~$ { return 404; }
location ~* ^/(wp-content/)?[^/]+\.(zip|tar|tar\.gz|tgz|gz|7z|rar)$ { return 404; }
location ~* ^/(installer|installer-backup)\.php$ { return 404; }
location ~* ^/wp-content/(updraft|ai1wm-backups|backups-dup-lite|backups-dup-pro|backup-db|backupwordpress[^/]*|uploads/backwpup[^/]*)(/|$) { return 404; }

The backup plugins protect their folders with their own .htaccess files, but Nginx ignores those, so on Nginx the last rule is the only protection. The plugins keep working: they read their folders from PHP.

What may break: download links to archives in the root or in wp-content and to .sql or .bak files, if you share such files on purpose. Archives in wp-content/uploads stay open. The rule is still not a backup policy: keep backups outside the web root or off the server, and delete migration leftovers. I wrote about automated backups with a bash script and about protecting wp-config.php before.

3. PHP files in the uploads folder

wp-content/uploads is the one folder PHP is allowed to write to, so it is where a weak form or an old plugin drops a backdoor. If the uploaded file is shell.php and the server runs it, the attacker has the site. Nothing in uploads needs to run as PHP: images, PDFs and videos are just files.

Check with a harmless test file, then delete it:

$ echo '<?php echo "PHP RUNS HERE";' > wp-content/uploads/test-php.php
$ curl -s https://example.com/wp-content/uploads/test-php.php
PHP RUNS HERE
$ rm wp-content/uploads/test-php.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-content/uploads/.*\.(php[0-9]?|phtml|phar|pht|phps)$ - [NC,R=404,L]
</IfModule>
location ~* ^/wp-content/uploads/.*\.(php[0-9]?|phtml|phar|pht|phps)$ { return 404; }

On Nginx this location must stand above location ~ \.php$: Nginx uses the first regex location that matches, so a rule below it never runs.

What may break: a rare plugin that keeps its own PHP scripts in uploads and opens them from the browser. More on this, together with file permissions, in hardening file permissions and PHP in uploads.

4. Logs and diagnostic pages

WP_DEBUG_LOG writes every PHP notice into wp-content/debug.log, and on many sites it was turned on once and forgotten. PHP on cPanel hosts writes error_log files next to the scripts. WooCommerce keeps gateway and webhook logs in uploads/wc-logs. A forgotten phpinfo.php from a server setup shows the whole PHP configuration. All of them give away full server paths, the hosting user name, versions of PHP and libraries, and sometimes payment errors with order data.

$ for p in /wp-content/debug.log /error_log /wp-content/error_log /phpinfo.php /info.php /test.php /server-status; do curl -s -o /dev/null -w "%{http_code} $p\n" https://example.com$p; done
200 /wp-content/debug.log
404 /error_log
200 /wp-content/error_log
404 /phpinfo.php
200 /info.php
404 /test.php
403 /server-status
$ curl -s https://example.com/wp-content/debug.log | head -2
[02-Nov-2026 09:14:27 UTC] PHP Warning:  Undefined array key "id" in /home/shopuser/public_html/wp-content/themes/shop/functions.php on line 214

One line, and the bot knows the hosting user, the path and the theme.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (\.log|(^|/)error_log)$ - [NC,R=404,L]
RewriteRule ^wp-content/(uploads/wc-logs|wflogs)(/|$) - [NC,R=404,L]
RewriteRule ^(phpinfo|php_info|info|test)\.php$ - [NC,R=404,L]
RewriteRule ^(server-status|server-info)(/|$) - [NC,R=404,L]
</IfModule>
location ~* (\.log|/error_log)$ { return 404; }
location ~* ^/wp-content/(uploads/wc-logs|wflogs)(/|$) { return 404; }
location ~* ^/(phpinfo|php_info|info|test)\.php$ { return 404; }

wflogs is the Wordfence data folder: Wordfence protects it with its own .htaccess, which again means nothing on Nginx. /server-status is usually closed by the host already, the rule is for the hosts that forgot.

What may break: opening a log in the browser on purpose. Read logs over SFTP or in the hosting panel; logging itself keeps working. Better still, turn off WP_DEBUG_LOG on production, or point it to a file outside the web root:

define( 'WP_DEBUG_LOG', '/home/user/logs/wp-debug.log' );

5. Folder listings

When a folder has no index.php or index.html and the server has listings on, a request to the folder returns a page with every file in it. WordPress puts an empty index.php into wp-content, plugins and themes, but not into the year and month folders of uploads, so on many shared hosts /wp-content/uploads/2025/05/ shows every file uploaded that month, including the ones that were never linked anywhere.

$ curl -s https://example.com/wp-content/uploads/2025/05/ | grep -o '<title>.*</title>'
<title>Index of /wp-content/uploads/2025/05</title>
Options -Indexes
# Nginx lists folders only when autoindex is on; make sure it is off
autoindex off;

On a few hosts .htaccess is not allowed to change Options, and the whole site answers 500 after this line. Open the home page right after saving; if it fails, remove the line and ask the host to turn listings off.

What may break: nothing on the site.

6. HTTPS only (HSTS)

A redirect from http:// to https:// still lets the first request go over plain HTTP, and on a public Wi-Fi that request can be answered by someone else. The Strict-Transport-Security header tells the browser to skip plain HTTP for this site completely, for as long as max-age says.

$ curl -sI https://example.com/ | grep -i strict-transport
strict-transport-security: max-age=31536000
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000"
</IfModule>
add_header Strict-Transport-Security "max-age=31536000" always;

This is the one rule that is hard to take back. If the certificate expires or HTTPS breaks, visitors who have been to the site cannot open it at all: browsers show no “continue anyway” button for HSTS sites. Turn it on only when HTTPS works on every page and the certificate renews by itself. I leave out includeSubDomains on purpose: on cPanel hosts subdomains like webmail or cpanel are not always on valid certificates. More about the HTTPS part of a site in the 12 checks.

7. Internal WordPress folders

The PHP files in wp-includes and wp-admin/includes are libraries: WordPress loads them from inside. Opened directly from the browser, some of them stop with a fatal error, and if the host shows errors, the error contains the full server path:

$ curl -s https://example.com/wp-includes/block-patterns.php
<b>Fatal error</b>: Uncaught Error: Call to undefined function add_theme_support() in /home/shopuser/public_html/wp-includes/block-patterns.php:9

These are the rules from the WordPress hardening guide, with 404 instead of 403:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-admin/includes/ - [R=404,L]
RewriteRule ^wp-includes/[^/]+\.php$ - [R=404,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [R=404,L]
RewriteRule ^wp-includes/theme-compat/ - [R=404,L]
</IfModule>
location ~* ^/wp-admin/includes/ { return 404; }
location ~* ^/wp-includes/[^/]+\.php$ { return 404; }
location ~* ^/wp-includes/js/tinymce/langs/.+\.php { return 404; }
location ~* ^/wp-includes/theme-compat/ { return 404; }

The real fix for the path in the error is display_errors = Off on production, but that is a php.ini setting the host controls. The rules close the most common entry points either way.

What may break: Multisite networks created before WordPress 3.5 that still serve files through wp-includes/ms-files.php. Scripts and styles in wp-includes are not PHP files and keep loading.

8. Files that show versions

readme.html in the root shows the WordPress version. readme.txt of a plugin shows its exact version in the “Stable tag” line, and vulnerability scanners compare it with their databases. Hiding the version in the page source does not help while these files are open:

$ curl -s https://example.com/wp-content/plugins/contact-form-7/readme.txt | grep -i 'stable tag'
Stable tag: 6.1.3
$ curl -s https://example.com/wp-admin/install.php | grep -o 'ver=[0-9.]*' | head -1
ver=7.1.4

The second line surprised me when I found it. WordPress does not load plugins on install.php and upgrade.php, so every “hide the version” setting in a plugin or theme does nothing there, and both pages are open to anyone. The rules close the files, the install pages, and upgrade.php for visitors without a login cookie (you still need it yourself when WordPress asks for a database update):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(readme\.html|license\.txt|wp-config-sample\.php|wp-links-opml\.php)$ - [NC,R=404,L]
RewriteRule ^(wp-content/plugins|wp-content/themes)/[^/]+/(readme|changelog|license)\.(txt|md)$ - [NC,R=404,L]
RewriteRule ^wp-admin/(install|setup-config)\.php$ - [NC,R=404,L]
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_
RewriteRule ^wp-admin/upgrade\.php$ - [NC,R=404,L]
</IfModule>
location ~* ^/(readme\.html|license\.txt|wp-config-sample\.php|wp-links-opml\.php)$ { return 404; }
location ~* ^/(wp-content/plugins|wp-content/themes)/[^/]+/(readme|changelog|license)\.(txt|md)$ { return 404; }
location ~* ^/wp-admin/(install|setup-config)\.php$ { return 404; }

Be honest with yourself about what this gives: a bot that cannot read versions tries all its exploits instead of the right one. It slows bots down; updating plugins is what closes the hole.

What may break: installing WordPress again over the same site needs the rule off.

9. Developer and build files

Themes and plugins built with Composer, npm, Gulp, webpack or Vite often reach production with their build files: composer.lock and package-lock.json list every library with its exact version, source maps (.map) give back the original unminified code with comments, and a Dockerfile, docker-compose.yml or deploy.php in the root describes the server.

$ for p in /composer.lock /wp-content/themes/shop/package.json /wp-content/themes/shop/dist/app.js.map /docker-compose.yml /deploy.php /README.md; do curl -s -o /dev/null -w "%{http_code} $p\n" https://example.com$p; done
200 /composer.lock
200 /wp-content/themes/shop/package.json
200 /wp-content/themes/shop/dist/app.js.map
404 /docker-compose.yml
404 /deploy.php
200 /README.md
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (^|/)(composer\.(json|lock)|package(-lock)?\.json|yarn\.lock|pnpm-lock\.yaml|gulpfile\.js|gruntfile\.js|webpack\.config\.js|vite\.config\.[jt]s|Dockerfile|docker-compose[^/]*\.ya?ml|wp-cli\.yml|deploy\.php|Makefile|php5?\.ini|php\.info)$ - [NC,R=404,L]
RewriteRule \.map$ - [NC,R=404,L]
RewriteRule ^[^/]+\.(md|ya?ml|sh|neon|dist)$ - [NC,R=404,L]
RewriteCond %{REQUEST_URI} !/wp-content/uploads/
RewriteRule ^wp-content/.+\.(md|txt|pot|po|mo|ya?ml|lock|dist|neon|sh)$ - [NC,R=404,L]
</IfModule>
location ~* /(composer\.(json|lock)|package(-lock)?\.json|yarn\.lock|pnpm-lock\.yaml|gulpfile\.js|gruntfile\.js|webpack\.config\.js|vite\.config\.[jt]s|Dockerfile|docker-compose[^/]*\.ya?ml|wp-cli\.yml|deploy\.php|Makefile|php5?\.ini|php\.info)$ { return 404; }
location ~* \.map$ { return 404; }
location ~* ^/[^/]+\.(md|ya?ml|sh|neon|dist)$ { return 404; }
location ~* ^/wp-content/(?!uploads/).+\.(md|txt|pot|po|mo|ya?ml|lock|dist|neon|sh)$ { return 404; }

I don’t block every .txt or .json file on the site, only in these places. A blanket rule breaks robots.txt, ads.txt, IndexNow key files, verification files for search consoles, manifest.json of themes and JSON animations.

What may break: browser developer tools stop showing the original source of minified scripts. For your own debugging, use a local copy of the site.

Check everything at once

After adding the rules, run the whole list. Everything except the first three lines should answer 404 (or 403 for the server’s own pages):

$ for p in / /robots.txt /wp-content/uploads/ /.git/config /.env /wp-config.php.bak /backup.zip /dump.sql /wp-content/debug.log /phpinfo.php /readme.html /wp-admin/install.php /composer.lock; do curl -s -A 'Mozilla/5.0' -o /dev/null -w "%{http_code} $p\n" https://example.com$p; done
200 /
200 /robots.txt
403 /wp-content/uploads/
404 /.git/config
404 /.env
404 /wp-config.php.bak
404 /backup.zip
404 /dump.sql
404 /wp-content/debug.log
404 /phpinfo.php
404 /readme.html
404 /wp-admin/install.php
404 /composer.lock

Then open a few pages, log in, submit a form and check that images, scripts and styles load. If something is missing, comment out one block at a time until you find the rule.

The same rules as switches in a plugin

I put these nine rules into my free plugin HelloAdmin Guard, on its Advanced tab, one switch per rule, in the same order. On Apache and LiteSpeed it writes them into .htaccess between its own markers. Before every change it keeps a copy of the file, then opens your home page, and if the page answers with a server error, it puts the old file back by itself. On Nginx it shows the same lines to copy. You can find it on GitHub.

If you would rather have someone go through your server and close these for you, write to me.