WordPress .htaccess generator
The standard WordPress rewrite rules for single-site or multisite, plus optional hardening — as an Apache .htaccess file or an nginx server block.
# Custom rules. WordPress rewrites everything between the
# BEGIN/END WordPress markers, so keep your own directives above them.
# Do not list the contents of directories that have no index file.
Options -Indexes
# Block direct requests for the WordPress credentials file.
<Files "wp-config.php">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
</IfModule>
</Files>
# Block direct requests for Apache configuration files.
<FilesMatch "^\.ht(access|passwd)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
</IfModule>
</FilesMatch>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
WordPress rewrites everything between # BEGIN WordPress and # END WordPress, so hardening rules are placed above that block. Back up the current file first. OpenLiteSpeed and IIS ignore .htaccess; on nginx, switch the web server above to get the equivalent location rules for the server block.
Quick answers
Where does the WordPress .htaccess file live?
In the site's root directory, alongside wp-config.php — the same folder wp-login.php is in. Multisite subdirectory networks use one .htaccess at the root; multisite subdomain networks do too, with different rewrite rules.
Why do my custom rules keep disappearing?
WordPress rewrites everything between # BEGIN WordPress and # END WordPress whenever permalinks are saved. Rules placed inside that block are overwritten; place custom rules above or below it instead, as this generator does.
Does this work on nginx?
nginx ignores .htaccess entirely, so choose nginx as the web server above: the generator then writes the same protections as location blocks and a try_files rule for the site's server block, which on most managed hosts only the provider can edit. Test with nginx -t before reloading. The HTTPS redirect loop guide explains when the redirect belongs at a proxy instead.
Why is there no nginx rule for directory listings?
nginx does not list directory contents unless autoindex is switched on, and it is off by default. Apache needs Options -Indexes because many Apache builds enable listings; on nginx the equivalent is simply not turning autoindex on.