Skip to content

08Website know-how & errors

Fix error 404 and set up redirects

404 Not Found on your website? Find the cause, set up 301 redirects, resolve redirect loops and repair WordPress permalinks at Nexthosting.

In short

A 404 means: there is nothing at this address. First check the spelling, upper and lower case, and the location of the file. With WordPress, a click on Einstellungen (Settings), Permalinks, Änderungen speichern (Save Changes) often helps. If a page moves, you point the old address to the new one with a 301 redirect.

The server understood the request but finds no matching file or page. To begin with, that is not a server error.

Where does the 404 occur?
On all subpages, only the home page works (WordPress)Re-save permalinks
After a move or new domainSet up 301 redirects
Browser reports "too many redirects"Resolve the redirect loop
  • Typo in the address or in the link.
  • Upper and lower case. On Linux servers, Bild.jpg and bild.jpg are two different files.
  • File is in the wrong folder, for example because an extra subfolder was created during the upload.
  • File was deleted or renamed.
  • Extensions: seite.html is not seite.htm.
  • Wrong domain assignment: The domain points to a different folder.
  • Spaces and umlauts in file names cause trouble. Use a-z, 0-9 and hyphens.

If the home page works but posts and pages show 404, the rewrite rules (permalink rules) in the .htaccess are missing or outdated.

  1. Log in to the WordPress admin area.
  2. Open Einstellungen (Settings), then Permalinks.
  3. Without changing anything, click Änderungen speichern (Save Changes). WordPress rewrites the rules.
  4. Still not loading? Check whether the .htaccess file exists in the main directory and is readable by the web server (File permissions).

The default WordPress rules look like this:

# 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

More help in Solving WordPress problems.

A good 404 page says that the page is missing and offers ways onward: search, home page, key sections. With WordPress the theme provides it (404.php). With a static site you create 404.html and assign it in the .htaccess:

ErrorDocument 404 /404.html

Important: the page must really deliver the status code 404, not 200. Otherwise search engines take it for a normal page (“soft 404”).

A 301 redirect sends visitors and search engines from an old address to a new one and passes on the search value of the old page. Use it when you move pages, change the structure or switch domains.

Redirect 301 /alte-seite/ https://meinprojekt.de/neue-seite/
RewriteEngine On
RewriteRule ^blog/(.*)$ https://meinprojekt.de/ratgeber/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?alte-domain\.de$ [NC]
RewriteRule ^(.*)$ https://neue-domain.de/$1 [R=301,L]
  • The rules belong in the .htaccess in the main directory. It works at Nexthosting (Apache); see .htaccess basics.
  • Place redirects before the WordPress rules (that is, above # BEGIN WordPress).
  • Redirect to the matching new page, not everything to the home page. Otherwise search engines treat it as a soft 404.
  • Test with curl:
Terminal window
curl -sI https://meinprojekt.de/alte-seite/ | grep -E "^HTTP|^location"

With WordPress, redirects also work with a plugin. For a few redirects the .htaccess is quicker.

Goal Code When
Page has moved permanently 301 (or 308) Rebuild, new domain
Temporarily elsewhere (maintenance, campaign) 302 (or 307) Short term
Page removed on purpose 410 “Gone for good”

The browser reports “ERR_TOO_MANY_REDIRECTS” or “The page redirected you too many times”. Two rules send visitors round in circles.

Common causes:

  • http is redirected to https, and a plugin redirects back to http.
  • In WordPress, “WordPress Address” and “Site Address” differ (www / without www, http / https).
  • A proxy or Cloudflare in “Flexible” mode talks to the server over http, and the server redirects to https again.
  • Two rules in the .htaccess (www and without www) work against each other.
How to resolve a loop
  1. Delete the site's cookiesRules out login loops
  2. Rename .htaccessDoes the site work now?
  3. Add rules back one by oneTest after each rule
  4. Check the WordPress addressesSettings, General
  5. Check the Cloudflare modeFull or Full (strict)

Follow the path with curl:

Terminal window
curl -sIL --max-redirs 10 https://meinprojekt.de/ | grep -E "^HTTP|^location"

Individual 404 pages do no harm. What matters is that important pages do not disappear. After a relaunch, check the list of your previous addresses and redirect them.

Why does my page show 404 although the file is there?

Section titled “Why does my page show 404 although the file is there?”

Usually the upper/lower case or the folder is wrong, or the domain points to a different folder.

Browsers remember it for a long time. So test new redirects first with 302 or with curl.

You should choose one variant as the main address and redirect the other. Example in .htaccess basics.