Websites and applications
Restore the WordPress .htaccess rules
On a server that supports Apache rules, WordPress uses rewriting to send friendly URLs to its entry file. These rules are stored in .htaccess.
If you deleted .htaccess or your posts return 404 errors, first make a copy of the current file. Then go to Settings > Permalinks and click Save Changes without changing the structure. WordPress will regenerate its block if the file is writable; if it cannot, it will show the rules you need to copy.
For a normal installation located in the domain root, the basic block is:
# 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
Replace only the block between # BEGIN WordPress and # END WordPress; do not delete security rules, redirects or settings added outside it.
Do not copy this example if WordPress is in a subdirectory, uses a public address different from the core's, or runs as Multisite. In those cases RewriteBase, the index.php target and other rules change. Always use the block generated by Permalinks or by Network Admin > Settings > Network Setup.
If the 404 persists, confirm that mod_rewrite is available, that .htaccess is read in that directory and that no earlier rule intercepts the request. Restoring this block does not fix domain paths, plugins or server settings that are the real cause.
Check the result
Test the home page, a post, a non-existent URL, admin access and a real file. The rules must not send existing images to index.php or turn an error into a home page with a 200 status code.
The basic block includes keeping the authorisation header that WordPress's current configuration uses. See the official Apache and .htaccess reference and preferably use the rules generated for your installation.
If a 500 appears after editing, restore the saved file and check the syntax and supported directives. Do not set 777 permissions to let WordPress write the file. If there were rules outside the block, keep their order and scope too.
You may also find useful
- Change the uploads folder and media organisation in WordPress Explains how to turn off date-based folders, change the WordPress uploads path and adjust files and...
- Control WordPress automatic updates Explains how to limit automatic core updates to minor versions, test major changes and avoid indefin...
- Deactivate a WordPress plugin without accessing the dashboard Helps you regain access to WordPress through recovery mode or by temporarily renaming the plugin's d...
- Enable WordPress Multisite Explains how to prepare, enable and complete a WordPress Multisite network with subdomains or subdir...
Something wrong or out of date? Tell us and we will review it.