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
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>
).
This should do it
RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With