.htaccesshttp-redirectmultilingualerrordocument

ErrorDocument 404 for a multi-lingual site


I'm facing a little problem which is causing a conflict in my website. when I'm for example on this page /en/pagenotexists/, how can I simply refer to /en/404.php?

I'm using the following directive in my .htaccess:

ErrorDocument 404 /404.php

I tried this solution but didn't work at all:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z]{2})/ /$1/404.php [R=404,L]

Solution

  • To show the content of lang specific 404.php with correct 404 status code you can use this internal rewrite rule:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-z]{2})/ $1/404.php [L]
    

    Then have your /en/404.php as this:

    <?php
    // return correct 404 status code
    http_response_code(404);
    
    // rest of the 404 handler content
    ?>