If your WordPress posts started returning 404 after .htaccess went missing, it’s tempting to paste a default file you found online. I tried that. It brought back the Hello World post at the site root, but it also wiped out a working redirect. The same file didn’t fix the post when the site was under /journal/.
I’d let WordPress generate the rules for the site’s own path instead. If you still have an .htaccess file, back it up and check what’s inside the WordPress markers before opening Settings > Permalinks. Just opening that screen as an administrator was enough to regenerate the file in my root test.
I tested this on Apache 2.4.71 with WordPress 7.1.5, PHP 8.3.37, MariaDB 11.8.10, and Twenty Twenty-Five 1.5. The single site used /%postname%/ permalinks.
The short answer
- Back up your existing
.htaccess. Review any custom directives between# BEGIN WordPressand# END WordPressbefore letting WordPress rewrite that block. - Keep custom rules outside the WordPress markers, but check their order and scope before moving anything.
- On a root install, open Settings > Permalinks as an administrator without changing the permalink structure. Use rules generated for your site’s path, not an old root example.
- Open a published post by its pretty permalink, then check every custom redirect for the expected status and destination.
The default .htaccess WordPress writes today
If you just need the file, here’s the block WordPress 7.1.5 wrote at the site root when I opened Settings > Permalinks with .htaccess missing. It should look like this:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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 WordPressCode language: Apache (apache)
It’s not quite the 2012 version you’ll find in most answers. Besides the three comment lines, it has an extra RewriteRule that passes the Authorization header on to PHP (some logins, like application passwords, need it on certain Apache setups; I didn’t test that part). If WordPress runs in a subfolder, RewriteBase and the last line change, see step 3.
You can paste this by hand, but only as the WordPress block. Your own rules stay above or below the markers, and if a file still exists, I’d rather let WordPress write the block itself, as shown below.
1. Back up .htaccess and check the WordPress block
Keep a copy of the whole file somewhere outside the public directory so you can compare it with the regenerated file or put it back if needed. If .htaccess is already missing, check your backups for any custom rules you need to recover. Regenerating the WordPress block won’t bring those back.
Look for # BEGIN WordPress and # END WordPress in the old file. The lines between them are the ones WordPress regenerates. If you find a hand-written redirect there, don’t assume it’ll survive. Before you move it outside the block, check which rules need to run first and whether the directive depends on anything around it. I’d try that change on a staging copy first rather than cut and paste every custom line at once. The same goes for security rules you added by hand, like an IP limit on wp-admin: they belong above the WordPress block.
In my /journal/ test, the redirect already above the markers kept working, and the AddType text/plain .guide directive below the markers still did its job. The redirect inside the block disappeared. Neither section outside the markers matched the original bytes exactly, so I’d compare the files and test what the rules do rather than expect an identical copy.
2. Open Permalinks as an administrator
Once the file is backed up and you’ve reviewed the custom rules, log in as an administrator and go to Settings > Permalinks. Leave the existing permalink structure alone. Check .htaccess after the screen loads.
On the root site, /hello-world/ returned 404 when the file was missing. A subscriber couldn’t open the Permalinks screen and the file stayed missing. When I opened the same screen as an administrator, WordPress created .htaccess and /hello-world/ returned 200. WordPress identified the page as the Hello World post, so this wasn’t just a URL that happened to return 200.
You don’t need to click Save Changes. It’s the usual advice and it works too: WordPress checks the form, then sends you back to this same screen, and loading the screen is what writes the rules. If opening it doesn’t write the file on your site, check whether WordPress can write it. If the screen gives you rules to add manually, use those for the WordPress block rather than replacing your entire file.
3. Use rules generated for your site’s path
The old root example I tried uses RewriteBase / and sends requests that don’t match a file or directory to /index.php. That was enough to bring back /hello-world/ at the root. But because I pasted it as the whole file, /old-reading-guide/ went from a 302 redirect to a 404.
It didn’t work as a drop-in replacement under /journal/. With both WordPress and the public site at that path, /journal/hello-world/ still returned 404 with the old root rules. I used the WordPress core writer through WP-CLI to generate the rules for that install. Here’s the part of the generated block that shows where those requests go:
RewriteBase /journal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /journal/index.php [L]Code language: Apache (apache)
After that, /journal/hello-world/ returned 200 and loaded the right post. /hello-world/ at the root still returned 404, which is what I wanted. The post belonged under /journal/.
4. Test more than the post that was broken
Start with a published post that failed before. Then request each old URL directly and check both the redirect status and where it sends you. If you have custom rules for files, request one of those files and check the response too.
Here’s what I checked after regenerating the /journal/ file:
| Request | What happened |
|---|---|
/journal/hello-world/ | **200**, with the Hello World post |
/journal/old-reading-guide/ | *302* to http://example.com/journal/sample-page/. This redirect was above the markers. |
/journal/reading-list/ | **404**. This redirect was inside the markers and was removed. |
/journal/wp-content/uploads/reading-guide.guide | *200* with Content-Type: text/plain. The AddType directive was below the markers. |
/hello-world/ | **404**. The post wasn’t served at the root. |
I wouldn’t call the repair done just because a post loads again. If a redirect fails, use your backup to find the original directive, check where it belongs, and test that URL again.
Limitations
This guide covers Apache single-site installs, not Multisite. I tested the Permalinks screen at the root. For /journal/, I used the WordPress core writer through WP-CLI, with both WordPress and the public site under /journal/. That’s not the same setup as keeping the WordPress files in a subdirectory while serving the public site at the root.