# 404 error after a migration or a permalink change

> Every page on the site returns a 404 error after moving to a new server, or right after touching the permalink settings: the cause is almost always that the server configuration redirecting URLs into WordPress didn’t come along with the move.

- Source canonique : [https://allaux.fr/en/wordpress-woocommerce/problemes/erreur-404-apres-migration](https://allaux.fr/en/wordpress-woocommerce/problemes/erreur-404-apres-migration)
- Langue : EN
- Dernière mise à jour : 2026-09-30

## Direct answer

> Go to Settings > Permalinks and click Save without changing anything: WordPress regenerates its rewrite rules. On Apache, make sure the .htaccess at the site root still holds the # BEGIN WordPress block and is writable. On Nginx that file is never read, and the try_files directive has to be added to the server configuration instead.

## How I go about it

1. **Telling the symptom apart** — I check whether only the homepage works, typical of a URL rewriting issue, or the whole site loops on redirects, usually a siteurl/home problem rather than a permalink one.
2. **Identifying the web server** — Apache and Nginx aren’t fixed the same way: Apache reads a .htaccess file at the root, Nginx needs its server block edited directly in its configuration.
3. **Re-saving the permalinks** — On Apache, I resave Settings > Permalinks to regenerate the .htaccess; on Nginx, I edit the server block to add the equivalent of try_files, since WordPress alone can’t do it.
4. **Checking custom post types** — If WooCommerce extensions or a page builder register their own post types, I check they’re active when re-saving so their rewrite rules get regenerated too.
5. **Checking siteurl and home** — I check that these two database options match the real domain after the migration, since a wrong siteurl produces a 404 or a redirect loop that has nothing to do with permalinks.

## What I handle regularly

- Every page on the site returns a 404 error after moving to a new host
- Only the homepage works, every other page returns a 404
- WooCommerce product pages are 404 while regular pages work fine
- A redirect loop appears after a domain name change
- Permalinks worked on the old server but not on the new one

## How permalinks work, and what breaks after a migration

WordPress’s "pretty" permalinks (Settings > Permalinks) work in two steps: WordPress rewrites raw URLs into clean paths, then the web server has to redirect every request back into index.php so WordPress can resolve it. On Apache, that redirection runs through rewrite rules in .htaccess; on Nginx, through an equivalent block in the server configuration.

After a migration to a new server, that .htaccess file, or that Nginx block, doesn’t come along automatically. On Apache, resaving Settings > Permalinks regenerates the .htaccess and is usually enough. On Nginx, the server block has to be edited directly, which WordPress can’t do on its own.

Custom post types, used by many WooCommerce extensions and by page builders for their templates, need their own rewrite rules regenerated too: re-saving permalinks does this, but only if the plugin registering them is active at that moment. A mismatch between the siteurl/home options and the real domain after migration produces a different kind of 404 or redirect loop, unrelated to permalinks: the two look similar to a merchant but are fixed differently.

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

## Re-saving permalinks isn’t always enough

> Resaving Settings > Permalinks or fixing an Nginx block takes minutes. If the URL structure changed compared with the old site, the old URLs also need mapping to the new ones with 301 redirects, a separate piece of work to avoid losing existing rankings.

## Related pages

- **Store migration** — A full platform migration needs far more than re-saving permalinks. ([/wordpress-woocommerce/migration](/wordpress-woocommerce/migration))
- **Broken navigation menu** — Another common symptom after a theme update or a server migration. ([/wordpress-woocommerce/problemes/menu-navigation-casse](/wordpress-woocommerce/problemes/menu-navigation-casse))
- **Urgent emergency fix** — A site returning 404 everywhere is a priority job. ([/services/depannage-urgent](/services/depannage-urgent))

## FAQ

### I just switched hosts and the whole site is 404, is that serious?

No, in the vast majority of cases it’s the .htaccess file or the Nginx configuration that didn’t come along with the migration. It’s usually fixed in minutes once identified.

### Why does only the homepage work and not the others?

That’s the typical sign of a URL rewriting issue: the homepage doesn’t depend on permalinks, the other pages do.

### I resaved the permalinks and nothing changed, why?

If the site runs on Nginx, resaving permalinks isn’t enough: unlike Apache, Nginx needs its server block edited directly, which WordPress can’t do on its own.

### Will I lose my rankings if the URLs change after the migration?

Not if the old URLs are redirected with 301s to the new ones. That’s work to plan separately from simply re-saving permalinks, especially if the URL structure changed.

### My product pages are 404 but my regular pages aren’t, why the difference?

Product pages depend on rewrite rules specific to WooCommerce, only regenerated if the plugin is active at the moment permalinks are re-saved.
