.htaccess on nginx: what to do when your rules stop working
· The AYT team · 9 min read

nginx doesn't read the .htaccess file at all. Its rules don't cause an error, they're simply ignored, so after a move to an nginx server the redirects, password-protected folders or PHP settings in .htaccess stop working without any warning. Each rule has to move somewhere else: into the nginx configuration if you run your own server, or into the equivalent settings in your hosting panel if you're on shared hosting.
Why nginx ignores .htaccess
On every request, Apache checks whether there's an .htaccess file in the requested folder and in every folder above it, then applies what it finds. That's convenient, because anyone with FTP access can change how the server behaves. The price is time lost on every request: for an image in wp-content/uploads/2026/05/, Apache looks for .htaccess in each of the five folders along the way.
nginx reads its configuration once, at start-up or on reload, and has no per-folder override. It's faster and more predictable, though only whoever runs the server writes the rules. On shared hosting that's your provider, who gives you settings in the panel instead.
WordPress permalinks (addresses like /about-us/) work on nginx too, through a rule your provider puts in the site's configuration:
location / {
try_files $uri $uri/ /index.php?$args;
}
That's why Settings → Permalinks works normally on nginx, with no .htaccess at all.
Signs your .htaccess rules aren't applied
- A redirect you had on the old host now leads to a 404 page.
- A password-protected folder opens without asking for anything.
- You set
php_value memory_limit 256M, and Tools → Site Health still shows the old value. - A cache or security plugin says it wrote its rules, but nothing changes.
- Files that were blocked on Apache (logs, backups inside the site folder) can be downloaded.
The last point is the most dangerous. Many plugins protect their folders with an .htaccess containing Deny from all. On nginx that protection doesn't exist, so the server itself has to block access to such files.
How to find out which web server your host uses
Run curl -I https://yourdomain.com in a terminal, or open F12 → Network in your browser, reload the page and look at the first request's headers. The server: line usually shows nginx, Apache or LiteSpeed. LiteSpeed reads .htaccess the same way Apache does. Some servers hide the header or sit behind Cloudflare (server: cloudflare); then ask your provider directly.
What to check when moving a site from Apache to nginx
Open the .htaccess file on the old host before the move and split it into pieces:
- The block between
# BEGIN WordPressand# END WordPressonly holds the permalinks. On nginx there's nothing to do for it. - Blocks written by plugins have markers too, for example
# BEGIN WP Rocketor a security plugin's name. Check in each plugin's settings what it does on nginx. - Everything left was written by hand: redirects, blocks, passwords, PHP settings. Go through them one by one with the table below and recreate them in the panel or in the nginx configuration.
After the move, test a few old addresses with redirects, a protected folder and the memory_limit value in Site Health.
What replaces each rule
| Rule in .htaccess | nginx equivalent | On shared hosting |
|---|---|---|
RewriteRule . /index.php (permalinks) |
try_files $uri $uri/ /index.php?$args; |
set by the provider |
Redirect 301 or RewriteRule ... [R=301] |
return 301 or rewrite ... permanent |
the panel's redirects page |
RewriteCond %{HTTPS} off (forced HTTPS) |
return 301 https://$host$request_uri; on port 80 |
the panel's HTTPS switch |
redirect to www or to the bare domain |
a separate server block |
the preferred address setting |
php_value, php_flag |
none; PHP-FPM reads .user.ini |
the PHP settings editor or .user.ini |
AuthType Basic and .htpasswd |
auth_basic and auth_basic_user_file |
password-protected folders |
Deny from or Require not ip |
deny 203.0.113.7; |
IP blocking |
Options -Indexes |
autoindex off; (the default) |
nothing to do |
ErrorDocument 404 /404.html |
error_page 404 /404.html; |
custom error pages |
Header set ... |
add_header ... |
response headers, if the panel offers them |
ExpiresByType, mod_deflate |
expires, gzip |
compression and browser caching, from the provider |
RewriteCond %{HTTP_REFERER} (hotlinking) |
valid_referers |
hotlink protection |
Below are concrete examples for the most common rules. You can only write them yourself if you run the server; on shared hosting, the table's last column is the one that matters.
Redirects
A redirect for a single page:
location = /old-page/ {
return 301 https://yourdomain.com/new-page/;
}
Several addresses with the same pattern, for example everything under /blog/ moved to the root:
rewrite ^/blog/(.*)$ /$1 permanent;
In nginx, permanent means 301 and redirect means 302. How to choose between them and avoid redirect chains is in the guide to the WordPress 301 redirect. If you have no server access, the Redirection plugin does the same redirects from WordPress, just a little slower.
HTTPS and www
On Apache, forced HTTPS is usually a three-line RewriteCond/RewriteRule block. On nginx, HTTP requests get a server block of their own that sends them to HTTPS:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://yourdomain.com$request_uri;
}
The same block settles www versus the bare domain. The rest of the HTTPS steps for WordPress, mixed content included, are in the HTTPS guide for WordPress.
PHP settings: .user.ini instead of php_value
The php_value and php_flag lines in .htaccess only work when PHP runs as an Apache module. On nginx, PHP runs through PHP-FPM, which reads a .user.ini file in the site folder instead:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
PHP rereads .user.ini every few minutes (every 300 seconds by default), so a change doesn't show straight away. Which values to pick is covered in the guides to memory_limit and upload_max_filesize and post_max_size.
Security plugins that start a firewall before WordPress through auto_prepend_file use the same mechanism: on nginx they write that setting to .user.ini, not .htaccess.
Password-protecting a folder and blocking IP addresses
The nginx equivalent of a password-protected folder:
location /archive/ {
auth_basic "Private area";
auth_basic_user_file /etc/nginx/passwords/archive;
}
The password file uses Apache's .htpasswd format, so you can usually reuse it. To block an address or a network:
deny 203.0.113.7;
deny 198.51.100.0/24;
Sensitive files and PHP in uploads
On Apache, WordPress security rules usually go in .htaccess. On nginx the server administrator adds them. The two basic ones: deny direct access to configuration files, and stop PHP from running in the uploads folder, where a .php file is almost always a backdoor.
location = /wp-config.php { deny all; }
location ~* ^/wp-content/uploads/.*\.php$ { deny all; }
location ~ /\.(?!well-known) { deny all; }
The last line blocks hidden files (.git, .env, even .htaccess) but leaves the .well-known folder, which Let's Encrypt needs.
Cache and security plugins on nginx
Cache plugins write rules to .htaccess for compression, browser caching and sometimes for serving cached pages without PHP. On nginx, the plugin's page cache still works through PHP, but compression and cache headers have to be done by the server. Some plugins generate a separate configuration file for nginx, which someone with server access has to include.
The same goes for blocking rules written by security plugins: check the plugin's settings for an nginx option, or whether your provider already handles that protection.
Automatic .htaccess converters
There are online tools that translate .htaccess into nginx rules. They're useful as a starting point, but check the output line by line. Converters often put everything in if blocks, which behave differently in nginx than you'd expect; the nginx documentation recommends location, return and try_files where possible. After any change, run nginx -t to check the syntax before reloading the server.
Frequently asked questions
Can I delete the .htaccess file?
On an nginx-only server the file does nothing. You can keep it, so you have the rules to hand if you ever move to Apache. One exception: some hosts put nginx in front of Apache, and there .htaccess still applies. Ask your provider if you're not sure.
What do I do with the .htaccess files in plugin folders?
Backup, form and logging plugins often put an .htaccess with Deny from all in their folder under wp-content, so the files there can't be downloaded. On nginx, check: open the direct address of a file in that folder in your browser. If it downloads, ask your provider to block the folder, or set the plugin to keep its copies outside the site's public folder.
Is a site faster on nginx?
nginx serves static files with very little memory and doesn't look for .htaccess on every request. A WordPress page's speed, though, depends more on PHP, caching and plugins; the details are in the guide to a slow WordPress site.
.htaccess on AYT hosting
AYT WordPress hosting runs on nginx, with no Apache, so .htaccess rules aren't read. You'll find the equivalents in the panel:
- redirects, on the domain's Redirects page, plus the "Force HTTPS Redirect" switch and "Preferred address" (with or without
www); - PHP settings (
memory_limit,upload_max_filesize,post_max_size,max_execution_time), in each domain's php.ini editor; - IP blocking, password-protected folders, hotlink protection, custom error pages, folder listings, MIME types and response headers, in the domain's settings;
- compression and browser caching, already on, on the Compression and caching page.

Running PHP in wp-content/uploads is blocked, and wp-config.php and hidden files (.git, .env) can't be downloaded, on every site. If you're coming from a host with Apache, tell us about any special rules you had in .htaccess when we do the site's free migration.
