Reputation: 2900
Am trying to make a custom 404 page for my website and am having .htaccess
file in the root directory where am using this rule
ErrorDocument 404 404.php //I want to redirect to 404
So when I change a valid file name like home.php
to home1.php
it doesn't redirect me instead it echo's 404.php
on that page
Side Note: 404.php
is in the root directory only
Upvotes: 13
Views: 23197
Reputation: 402
In my case, using an Ubuntu distribution, the directive ErrorDocument
has no effect if it is in the .htaccess
in htdocs
directory or elsewhere: it turned out that it should be put in the proper /etc/apache/sites-enabled/*.conf
file, inside the <VirtualServer>
directive (for example, if the website is providing https pages, inside the directive <VirtualHost *:443>
).
Upvotes: 1
Reputation: 21023
you could do the following to 404 old pages with your htaccess
RewriteEngine on
ErrorDocument 404 /404.php
but i would personally recommend
RewriteEngine on
RewriteRule home.php /home1.php [R=301,L]
as this would do a 301 redirect from the old page name to the new page name, so any cached search engine results would still end up at the correct page instead of hitting a 404
Upvotes: 4
Reputation: 20913
In your .htaccess
file, you should be able to use:
RewriteEngine on
ErrorDocument 404 /404.php
You can set additional error documents using this method, but I'd put them in a separate errors directory:
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
Upvotes: 8
Reputation: 24733
This should do it
RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php
Upvotes: 25