.htaccess not redirecting to 404.php instead shows page name
This should do it
RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.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
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
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>
).