# Fixing WordPress Permalink and 404 Issues

Source: https://support.kapsulehost.com/en-nz/wordpress-permalink-issues

If your WordPress pages are returning 404 errors when they should exist, or links within your site are broken after a migration or plugin change, the most common fix is to flush (regenerate) your WordPress rewrite rules.

### The Quick Fix: Flush Permalinks

1. Log in to your WordPress admin at `yourdomain.com/wp-admin`
2. Go to **Settings > Permalinks**
3. Without changing anything, click **Save Changes**

This regenerates the `.htaccess` file and flushes the rewrite rules. In most cases, 404 errors will be resolved immediately after doing this.

### If You Cannot Access WordPress Admin

If the 404 issue is preventing you from logging in or accessing admin:

1. Connect to your site via SFTP. See [SFTP Access](https://support.kapsulehost.com/en-nz/sftp-access)
2. Navigate to the root of your WordPress installation
3. Open the `.htaccess` file (see [Understanding .htaccess on KapsuleHost](https://support.kapsulehost.com/en-nz/wordpress-htaccess))
4. Replace the contents between the WordPress comment markers with the default WordPress rules:

```
# 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
```

5. Save the file
6. Log in to WordPress admin and re-save Permalinks as above

> **Warning:** Only modify the `.htaccess` rules between the `# BEGIN WordPress` and `# END WordPress` markers. Anything outside these markers is added by other plugins or server configurations and should not be removed.

### Permalink Settings After Migration

If you have recently [migrated your site to KapsuleHost](https://support.kapsulehost.com/en-nz/migrating-to-kapsule), your old `.htaccess` file may contain rules from a different server environment. After migration:

1. Go to **Settings > Permalinks**
2. Select your preferred URL structure (for example, **Post name**)
3. Click **Save Changes**

> **Tip:** If you are using a custom permalink structure, note it down before flushing. The flush does not change your chosen permalink format, it just regenerates the rules that make it work.

### If the Issue Persists

Check the following:

- Confirm `mod_rewrite` is enabled on the server (KapsuleHost enables this by default)
- Ensure the `.htaccess` file in your site root is writable by the web server
- Deactivate recently installed plugins one at a time to check for conflicts

If none of these resolve the issue, open a support ticket in KPanel under **Support**.
