redirect to 404 page php htaccess code example

Example 1: htaccess 404 redirect

ErrorDocument 404 /404.html

Example 2: redirect 404 to index htaccess

ErrorDocument 404 /index.php

Example 3: how to redirect 404 error page in php

Try this in your .htaccess:

ErrorDocument 404

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]
Here,The ErrorDocument redirects all 404s to a specific URL

The Rewrite rules map that URL to your actual 404.php script. The RewriteCond regular expressions can be made more generic if you want, but I think you have to explicitly define all ErrorDocument codes you want to override.

NOTE: Replace


Php Example