Search code examples
php.htaccess

404 path for php document


I created a .htaccess file with an ErrorDocument 404 that redirects me to a PHP page. My goal is to get the user's entered url, e.g.: User enters: https://test.de/example //not available He gets redirected to https://test.de/test.php and I need the old path /example


Solution

  • Just add this to your .htaccess

    ErrorDocument 404 /404.php
    

    In this file you can retrieve the old path (/example) with

    $_SERVER["REQUEST_URI"]