Every post shows 404 but the homepage works
WordPress sends each post address to index.php through rewrite rules. When those rules are missing or out of date, every post and page shows “Not Found”. Saving the permalinks rebuilds them.
- Sign in to WordPress and go to Settings › Permalinks.
- Click Save Changes without changing anything. WordPress rebuilds its rules and rewrites
.htaccessif it can. - Reload a post. If it loads, you are done.
- If WordPress says it cannot write to
.htaccess, restore the file by hand, as in the next section. - Still 404? Note your current permalink setting, choose Plain and save.
- If posts now load, with addresses like
?p=123, the rewrite rules are at fault. Switch back to your setting, save, and restore.htaccessbelow.
Restore the default .htaccess file
LiteSpeed reads the same .htaccess rules as Apache. One wrong line can take the whole site down, so keep a copy before you change it.
- In cPanel, open File Manager and go to the folder WordPress is in, usually
public_html. - If you do not see
.htaccess, click Settings, tick Show Hidden Files (dotfiles) and click Save. - Select
.htaccessand click Download, so you have a backup. - Edit
.htaccess. If there is none, click + File and create it. - Make sure it has the default rules for a site at the domain’s root:
# 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 - For a site in a subfolder, such as
/blog, changeRewriteBase /toRewriteBase /blog/and the last rule toRewriteRule . /blog/index.php [L]. - Keep your other rules, such as an HTTPS redirect, outside the
# BEGIN WordPressand# END WordPresslines. WordPress overwrites what is between them. - Save and reload a post. If the site shows a 500 error, upload your copy back and see how to fix the WordPress 500 error.
- If the rules are right and posts still show 404, ask your host to check that URL rewriting (
mod_rewrite) and.htaccessfiles are allowed for your site.
One page or post shows 404
If the rest of the site works, the problem is that page. Its address changed, or it is no longer published.
- In WordPress, open Pages or Posts and search for its title.
- If it is in Trash, click Restore, then publish it. WordPress restores trashed items as drafts.
- If its status is Draft or Pending, publish it. Scheduled and Private items show 404 to visitors.
- Compare its address with the link that fails. If a page’s slug, the last part of the address, changed, old links break. WordPress redirects old post slugs on its own, but not page slugs.
- Add a 301 redirect from the old address to the new one with a redirect plugin, such as Redirection.
- Or download a copy of
.htaccess, then addRedirect 301 /old-page/ https://example.com/new-page/above# BEGIN WordPress, with your own addresses. - If the page was deleted for good, redirect its address to the closest page.
- Purge your cache plugin or CDN, so it stops serving the old 404.
404 error after a migration
After a move to a new host or domain, 404s usually come from a site address that still points to the old place, a missing .htaccess file, or links that still use the old domain.
- Download a backup of the database in cPanel › Backup before you change anything.
- Open Settings › General. Set WordPress Address (URL) and Site Address (URL) to your new address, such as
https://example.com. - If you cannot sign in, download a copy of
wp-config.php, then adddefine( 'WP_HOME', 'https://example.com' );anddefine( 'WP_SITEURL', 'https://example.com' );to it, above the “stop editing” comment. - Check that
.htaccesscame across. Hidden files are often left behind in a move. If it is missing, restore it as above. - Replace the old domain in your content with a tool that handles serialized data, such as
wp search-replacein WP-CLI or a search-and-replace plugin. - Go to Settings › Permalinks and click Save Changes.
- Browser says “too many redirects” instead? See how to fix too many redirects in WordPress.
Images show 404
WordPress keeps images in wp-content/uploads, in year and month folders. A broken image means its file is missing, or its address points somewhere else.
- Right-click a broken image, open it in a new tab and note its address.
- In File Manager, check that the file is in that folder under
wp-content/uploads. - If the address still uses the old domain, replace it as in the migration steps above.
- If the file is missing, upload it again from your old host or a backup.
- Match the case of the file name. Linux servers treat
Photo.jpgandphoto.jpgas two files. - If only resized copies such as
photo-300x200.jpgare missing, regenerate them with a plugin such as Regenerate Thumbnails, or runwp media regenerate --only-missingover SSH. - If
wp-config.phpdefinesUPLOADS, check that the folder it names exists.
Custom post types show 404
Plugins that add content types, such as products, events or portfolios, add their own address rules. WordPress may not use them until you rebuild its rules.
- After you activate such a plugin, go to Settings › Permalinks and click Save Changes.
- Save the permalinks again after you change a content type’s slug in the plugin’s settings.
- If the content type came with your theme, it is gone when you switch theme, and its pages show 404. Switch back, or move it to a plugin.
HostUpIndia WordPress hosting
HostUpIndia WordPress plans come with WordPress pre-installed on LiteSpeed, NVMe storage, cPanel and free SSL. Daily backups are kept 30 days, so there is a copy from before a change that broke your links.
- From ₹149 a month on 3-year billing. Prices exclude 18% GST. See WordPress plans.
- Support tickets and email are received 24 hours a day, 7 days a week; WhatsApp is open for questions from 10 am to 7 pm IST, Monday to Saturday.
- Free website migration by the HostUpIndia in-house team.
- More help guides.
