i have following of 404 page....
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+)$ ?file=$1 [L]
but it is showing this page to all directories and page event the root directory
i have following of 404 page....
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+)$ ?file=$1 [L]
but it is showing this page to all directories and page event the root directory
Make sure that the rewrite engine is turned on in .htaccess or your vhost declaration. Also, you need to check if directories or symlinks exist for the request. Here's an updated example:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.+)$ /404.php?page=$1 [L]
Apache also has a document handler for 404 / file-not-found responses. You can access the file requested via the REQUEST_URI
header. Here's an example with the corresponding Apache rules and PHP 404 error handler file:
.htaccess:
ErrorDocument 404 /404.php
404.php:
<?php
echo "Tried to access: {$_SERVER['REQUEST_URI']}";
?>
I prefer the ErrorDocument handler, as Apache will still log the 404 response code, which is useful for generating analytics for missing page / broken links.