Skip to content

WordPress permalinks broken after migration to cPanel

How to fix WordPress permalinks that return 404 after migrating to cPanel — .htaccess, rewrite rules, and the difference between Apache and LiteSpeed handling.

Right after a migration, the homepage works but every other page returns 404. That’s almost always WordPress permalinks — the rewrite rules from the old host didn’t make it, or .htaccess is missing, or it exists but isn’t readable. The fix is a one-liner; recognizing the symptom saves you from chasing ghosts.

What’s happening

WordPress uses “pretty permalinks” by default — /category/post-name/ instead of /?p=123. Pretty permalinks require the web server to rewrite those URLs to index.php?... before WordPress processes them. On Apache and LiteSpeed, that’s done via .htaccess with mod_rewrite rules WordPress generates. When .htaccess is missing, unreadable, or the web server isn’t honoring it, only the homepage works (because index.php serves it without rewriting) and every other URL 404s.

How to verify

Check whether .htaccess exists and contains the WordPress block:

ls -la ~/public_html/.htaccess
cat ~/public_html/.htaccess
wp option get permalink_structure
curl -I https://example.com/sample-page/

The .htaccess should contain a # BEGIN WordPress block with rewrite rules. The permalink structure option should match what was configured before migration. curl should return 200, not 404.

The fix

  1. Confirm Apache or LiteSpeed honors .htaccess. On cPanel, both do by default. If your server admin disabled .htaccess overrides at the vhost level, you have a different problem — check AllowOverride All in the vhost config.

  2. Recreate .htaccess by re-saving the permalinks. WP-CLI:

    wp rewrite flush

    Or via the dashboard: Settings > Permalinks > Save Changes (don’t change anything, just save).

  3. If WP-CLI says success but .htaccess still doesn’t exist, check file permissions on public_html. WordPress needs write access to the document root to create .htaccess:

    ls -ld ~/public_html

    755 with ownership matching the cPanel user is the right state.

  4. Manually create .htaccess if WordPress can’t. Drop this in ~/public_html/.htaccess:

    # 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

    Set chmod 644 ~/public_html/.htaccess after creation.

  5. For Multisite, .htaccess is different. Use the network setup-generated block specific to subdomain or subdirectory Multisite, exactly as WordPress provided.

  6. LiteSpeed-specific: LiteSpeed honors .htaccess natively but also has its own caching directives. If LiteSpeed Cache plugin is installed, it writes a # BEGIN LSCACHE block above the WordPress block. Both should be present. Order matters — LSCACHE first, then WordPress.

  7. Test each permalink type after the fix:

    curl -I https://example.com/sample-page/
    curl -I https://example.com/2024/01/01/sample-post/
    curl -I https://example.com/?p=1

    All should return 200 (or 301 if you have HTTPS forced). The pretty URL and the ?p=1 query string should both reach the same content.

  8. If permalinks still 404 after .htaccess is present and correct, check ModSecurity logs. Aggressive ModSec rules occasionally block legitimate WordPress URL patterns. cPanel > ModSecurity Tools > Hits List shows blocked requests. Whitelist the rule for your site if you confirm the block is overzealous.

Stack Harbor handles permalink and rewrite configuration as part of enterprise WordPress migrations and ongoing ops.