Multiple error 404s?

Hello,

I have a website in multiple languages, English pages are in the root, but each language is within its own subfolder and all home pages are titled index.html. I want to know if it’s possible to redirect any error 404 to the index.html within the current directory a visitor is in rather than defaulting back to the root index.html?

I believe some redirect code within the .htaccess file can do this for a single entry yet unsure about multiple entries, so I thought best to ask the experts. What say the experts to this conundrum?

Morrile

Morrile,

Add the following to each subdirectory’s .htaccess file:

ErrorDocument 404 /{subdirectory name}/index.html

You might be able to code this into the DocumentRoot’s .htaccess file but only IF the subdirectory names are captured and used in a redirection like

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|es|de|yadda|yadda)/ $1/index.html [R=404,L]

Just note that the list of language directories needs to be specified (mod_rewrite is not psychic) so it can be used in the redirection; also, do NOT specify a filename in the RewriteRule’s regex because it’s a 404 request!

Regards,

DK

Hello dklynn,

What a star you are :slight_smile: but before I get too excited I just want to check something?I didn’t realise you could have more than one .htaccess file, so I just need to place an edited copy into each language sub-folder and change {subdirectory name} to match the folder name?

Many thanks,
Morrile

yes

:slight_smile:

As I thought. Sorry for perhaps asking the obvious, brain was not working well yesterday.

Many thanks again for your splendid assitance.

Morrile

No worries. Hope the assistance helped as well :slight_smile: