Search code examples
phpwebhttp-status-code-404

Convert .htaccess rewrite rule for showing a custom 404 to be php-fpm friendly


I'm reinstall server on Ubuntu 20.04 with control panel "Hestia" with php-fpm support. But i have 404 error in front page domain.com/ if i use in .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en/|ua/|) $1404.php [L]

All others pages and front page if i add /index ( domain.com/index ) works fine. If I comment this rules - all works and front page too, but i not have my 404 page.

Please help convert my .htaccess to php-fpm friendly. What do I need to do?


Solution

  • Using rewrite rules for non-existing files to a 404 handler is not the standard way to show a custom 404. I would implement this using the ErrorDocument directive.

    • In $DOCUMENT_ROOT/.htaccess:

      ErrorDocument 404 /404.php
      
    • In $DOCUMENT_ROOT/en/.htaccess:

      ErrorDocument 404 /en/404.php
      
    • In $DOCUMENT_ROOT/ua/.htaccess:

      ErrorDocument 404 /ua/404.php