How Do I Fix a Broken .htaccess in WooCommerce?
Why This Happens
The .htaccess file, on Apache-based hosting, contains the rewrite rules that translate clean, readable URLs into the actual WordPress page requests behind them. This file can go missing or become corrupted from a server migration, a hosting-side reset, a security plugin's own rewrite rules conflicting with WordPress's, or simply a manual editing mistake — and when it's broken, nearly every non-homepage URL on the site can start returning a 404, WooCommerce pages included.
Common Causes
- A server migration or restore that didn't correctly transfer the existing
.htaccessfile, or reset it to a generic default. - A security plugin or CDN writing its own rules into
.htaccessin a way that conflicts with or overwrites WordPress's expected block. - Manual editing (adding a custom rule, a redirect) that introduced a syntax error, breaking the whole file's processing.
- File permission issues preventing WordPress from writing to the file when it needs to regenerate rules automatically.
How to Fix It
- Go to Settings → Permalinks and click Save without changing anything — this forces WordPress to regenerate its standard rewrite block, resolving most cases.
- If that doesn't work, check file permissions on
.htaccessand its containing directory, ensuring WordPress can actually write to it. - If a plugin's own rules are suspected of conflicting, temporarily deactivate it and regenerate permalinks again to test.
- As a last resort, manually recreate the file with WordPress's standard rewrite block, available in the WordPress documentation, then re-add any legitimate custom rules afterward.
Site returning widespread 404 errors and need this fixed urgently? See WooCommerce fixes.
Safely testing and replacing .htaccess
- Download a copy first through FTP or the host's file manager, so any change can be undone.
- Rename the file and test. Rename
.htaccessto.htaccess-oldand load the site. If a 500 error disappears, the old file had a syntax error, and the server's error log will name the line. If the homepage loads but inner pages return 404, save the Permalinks screen to write a fresh file. - Know the standard block. A default WordPress install uses:
# 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 - Check which server you're on. Nginx doesn't read
.htaccessat all. If the host runs Nginx, editing the file changes nothing, and the equivalent rule lives in the server configuration.