vtni
vtni

Reputation: 980

.htaccess 404 different errorpages

i have a multilanguage site with example.com/en/ and /fr/, /de/ and so on.

now i wanted to have a default errorpage, e.g. in example.com/en/404.php (in all language directories)

If someone calls example.com/de/site-not-existing i want show example.com/de/404.php. this should also be available for /en/ and /fr/

my problem is that i cannot use ErrorDocument in my .htaccess, because it's only possible to set one ErrorDocument.

is there another solution? i thought about creating a htaccess in each language directory, but it would be better, if i can set all from the one in the root directory.

Upvotes: 1

Views: 48

Answers (2)

anubhava
anubhava

Reputation: 785108

You need to use mod_rewrite rules for this in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de|fr)/ /$1/404.php [L,NC]

Upvotes: 1

Justin Kiang
Justin Kiang

Reputation: 1290

Have all your 404 go to a 404.php, and then utilizing $_SERVER['REQUEST_URI'], you can detect which language variant the user came from that landed them to the 404 page, and redirect them to the appropriate 404.php

Upvotes: 0

Related Questions