# How to Diagnose and Fix 404 Errors on WordPress (Permalinks, .htaccess and Missing Files)

> WordPress 404 errors on pages and posts that definitely exist almost always come down to one of four causes. Working through them in order is the fastest route to a fix.

Source: https://www.kualo.com/knowledgebase/wp-troubleshooting/how-to-diagnose-and-fix-404-errors-on-wordpress-permalinks-htaccess-and-missing-files
Updated: 2026-06-09

---

WordPress 404 errors on pages and posts that definitely exist almost always come down to one of four causes. Working through them in order is the fastest route to a fix.

## Before you start

If your whole site is returning a 404 rather than just individual pages or posts, jump straight to [Cause 3](#cause-3-wrong-site-url-after-a-migration-or-clone) first, as a wrong Site URL after a migration is the most likely culprit in that scenario.

Once you have applied a fix, clear your cache and your [browser cache](/knowledgebase/domains-dns-ns/how-to-clear-your-browser-cache) before testing. Cached responses can make a 404 appear to persist even after the underlying problem is resolved. Most caching plugins have a "clear cache" or "purge cache" button in the WordPress admin toolbar or their settings page. If you are using LiteSpeed Cache, see [Configuring LiteSpeed Cache with WordPress](https://www.kualo.com/knowledgebase/wordpress-optimisation/configuring-litespeed-cache-with-wordpress) for guidance.

---

## Cause 1: Permalink settings out of sync

This is the most common cause of 404 errors on pages and posts. WordPress stores its URL rewrite rules in the `.htaccess` file, and those rules can fall out of sync after a migration, a WordPress core update, or a manual edit to `.htaccess`. The fix is to resave your permalink settings, which forces WordPress to regenerate and rewrite the rules.

1. Log in to your WordPress admin dashboard.
2. Go to **Settings > Permalinks**.
3. Without changing anything, click **Save Changes**.

WordPress will rewrite the `.htaccess` file with fresh rewrite rules. Test your site straight away. If pages and posts load correctly, you are done.

:::tip
If you are not sure which permalink structure you were using before, check with a colleague or look at the URL format of any posts that were working previously. The most common structure is **Post name** (`/%postname%/`).
:::

---

## Cause 2: Missing or broken .htaccess file

If resaving permalinks does not help, the `.htaccess` file itself may be missing, empty, or corrupted. You can check and restore it using [File Manager in cPanel](https://www.kualo.com/knowledgebase/cpanel-files-ftp/how-to-use-file-manager-in-cpanel).

### Locating the file

1. Log in to cPanel and open **File Manager**.
2. Navigate to your WordPress root directory. For a main-domain install this is usually `public_html`; for a subdirectory install it will be something like `public_html/blog`.
3. Dotfiles are hidden by default. Click **Settings** (top right) and tick **Show Hidden Files (dotfiles)**, then click **Save**.
4. Look for a file named `.htaccess` in the WordPress root.

### Restoring the file

If the file is missing, empty, or does not contain the WordPress rewrite block, you can recreate it. Right-click in the directory and choose **Create New File**, name it `.htaccess`, then open it with the code editor and paste in the standard WordPress block:

```apacheconf
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
```

If your WordPress install is in a subdirectory (for example `public_html/blog`), the `RewriteBase` and the final `RewriteRule` need to reflect that path. Resaving your permalink settings (Cause 1 above) handles this automatically, so always try that first.

:::warning
This boilerplate block contains only the core WordPress rewrite rules. Any rules previously added by caching plugins (such as LiteSpeed Cache), security tools, or other services will not be present. After pasting in the boilerplate, go back into each plugin or service that may have written to `.htaccess` and re-save its settings so those rules are restored. For LiteSpeed Cache, saving the cache settings from the plugin dashboard will rewrite its rules automatically. If you are unsure what was in your previous `.htaccess`, consider restoring from a backup instead - see the JetBackup option below.
:::

:::warning
The `.htaccess` file must live in the WordPress root directory, not inside `wp-admin` or `wp-content`. Placing it in the wrong folder will have no effect.
:::

### Restoring from a JetBackup file backup

If your `.htaccess` was working correctly before a recent change, you may be able to restore the previous version directly from a backup rather than recreating it from scratch. JetBackup in cPanel keeps up to 30 days of file backups and lets you restore individual files, which means you can recover a version of `.htaccess` that already contained all your custom rules. See [Restoring file backups in cPanel](/knowledgebase/cpanel-backups/restoring-file-backups-in-cpanel) for a full walkthrough.

### File permissions

For WordPress to write to `.htaccess` automatically when you save permalink settings, the file needs to be writable by the web server. The correct permission is `644`. If the file has a more restrictive permission, WordPress will display the correct block and ask you to paste it manually instead of writing it itself. You can check and change permissions in File Manager by right-clicking the file and choosing **Change Permissions**.

For more detail on diagnosing `.htaccess` problems in general, see our guide to [troubleshooting .htaccess issues](https://www.kualo.com/knowledgebase/dev-server/troubleshooting-htaccess-issues).

---

## Cause 3: Wrong Site URL after a migration or clone

If 404 errors appeared after moving your site to a new domain, or after cloning it, the Site URL and Home URL stored in the WordPress database may still point to the old domain. WordPress uses these values to build every URL on the site, so a mismatch causes widespread 404s - often including the admin area itself.

### Checking and updating via WordPress admin

1. Go to **Settings > General** in your WordPress dashboard.
2. Check the **WordPress Address (URL)** and **Site Address (URL)** fields.
3. If either still shows the old domain, update both to the new domain (including `https://` if you have SSL active).
4. Click **Save Changes**.

:::info
Both fields usually need updating, not just one. Missing either can leave parts of the site broken.
:::

### Updating via WP Toolkit

WP Toolkit includes a domain and URL management tool that can update the Site URL and Home URL for you. Open WP Toolkit in cPanel, find your WordPress installation, and look for the domain or URL change option in the installation settings. [confirm: exact label and location of the URL/domain change tool in WP Toolkit's current UI]

### Updating URLs in the database with WP-CLI or a plugin

After a migration, old URLs may also be embedded throughout your database content - in post bodies, widget settings, and serialised option values. A simple Site URL update will not catch these.

You can run a search and replace across the database using either of the following approaches:

- **[WP-CLI](/knowledgebase/dev-cli/using-wp-cli-on-kualo-hosting)** (via [SSH](/knowledgebase/dev-cli/using-ssh-on-kualo-hosting-a-getting-started-guide)): `wp search-replace 'https://old-domain.com' 'https://new-domain.com' --all-tables` handles serialised data correctly and is the fastest option if you are comfortable using the command line.
- **Better Search Replace plugin**: a free WordPress plugin that provides a safe, guided search-and-replace interface directly from the admin dashboard, with a dry-run option so you can preview changes before applying them.

### If the admin area is inaccessible

If the wrong Site URL has locked you out of the WordPress admin entirely, please [contact our support team](https://www.kualo.com/knowledgebase/getting-started/how-to-create-a-support-ticket-in-mykualo). We can update the values at the database level for you.

For a full walkthrough of moving WordPress to a new domain, including database URL updates, see [Moving WordPress to a different domain in 5 steps without downtime](https://www.kualo.com/knowledgebase/wp-security/moving-wordpress-to-different-domain-in-5-simple-steps-without-any-downtime).

---

## Cause 4: Missing or damaged WordPress core files

If specific admin pages or built-in WordPress features return a 404 but the rest of your site loads normally, one or more core WordPress files may be missing or corrupted. This can happen after a failed update or an incomplete file transfer.

### Using WP Toolkit (recommended)

The safest way to fix this is to use WP Toolkit's integrity check, which compares your core files against the official WordPress release and restores any that are missing or changed - without touching your content, themes, or plugins.

1. Open **WP Toolkit** in cPanel.
2. Find your WordPress installation and click on it to open the details.
3. Run the integrity check. WP Toolkit will list any files that differ from the official release.
4. Restore the affected files.

For a full walkthrough, see [Checking WordPress integrity with WP Toolkit](https://www.kualo.com/knowledgebase/wp-toolkit/checking-wordpress-integrity-with-wp-toolkit).

### Using WP-CLI via SSH

If you prefer the command line, or do not have WP Toolkit available, you can use WP-CLI to verify and reinstall core files without affecting your content, themes, or plugins.

To check the integrity of your core files:

```bash
wp core verify-checksums
```

This compares every core file against the official WordPress checksums for your installed version and reports any files that are missing or have been modified.

If the check finds problems, reinstall the core files with:

```bash
wp core download --skip-content --force
```

The `--skip-content` flag leaves your `wp-content` directory (themes, plugins, and uploads) untouched. The `--force` flag overwrites existing core files with fresh copies from WordPress.org.

:::tip
Run both commands from your WordPress root directory over SSH. If you are unsure how to connect via SSH, see [How to configure cron jobs](/knowledgebase/dev-cli/how-to-configure-cron-jobs) for a pointer to SSH access, or contact our support team.
:::

---

## A note on rewrite rules and LiteSpeed

Our servers run LiteSpeed as the web server. LiteSpeed reads and honours `.htaccess` rewrite rules in exactly the same way as Apache does, so no additional server-level configuration is needed on your part. If your `.htaccess` block is correct and in the right place, rewrites will be active.

If you have worked through all four causes above and 404 errors persist, please [raise a support ticket](https://www.kualo.com/knowledgebase/getting-started/how-to-create-a-support-ticket-in-mykualo) and we will investigate at the server level.

---

## Quick reference: common mistakes to avoid

- File Manager hides dotfiles by default - enable **Show Hidden Files** before looking for `.htaccess`.
- The `.htaccess` file belongs in the WordPress root, not in `wp-admin` or `wp-content`.
- After a migration, update both Site URL and Home URL, not just one.
- Always clear your cache after making any of the changes above before testing.
- If you are on a subdirectory install, resaving permalinks sets the correct `RewriteBase` path automatically.
- If you restore a boilerplate `.htaccess`, re-save the settings for any plugin or service that previously wrote rules to it (such as a caching plugin) so those rules are added back.


---

_Source: Kualo Knowledgebase — https://www.kualo.com/knowledgebase/wp-troubleshooting/how-to-diagnose-and-fix-404-errors-on-wordpress-permalinks-htaccess-and-missing-files · © Kualo Ltd._
