Forum Moderators: phranque
I need to be redirect my visitors to another page when the file they are looking for is not found. At the moment I am using the following in an .htaccess file
RewriteEngine on
RewriteBase /mod
RewriteRule ^(.*) [mydomain.com...]This unfortunately redirects even when the file is found. Is there any way to redirect only when a real file is not found? I can’t just use standard custom error 404 pages because I need to know the name of the non existent file.
Thanks a lot, any help would be much appreciated.
Also, be aware that if you *never* return a 404 error, then some search engine spiders may consider your site to be an "infinite URL space" and may limit the depth of their spidering.
Requests for pages which are not replaced by a newer, relevant page should return a 404. Spidering problems as noted above, and duplicate content issues may ensue if you redirect *all* missing pages to one page.
You may be able to modify your php code to get the requested page name from the request_uri or request_filename variable, and then you can use the standard ErrorDocument 404 directive with your script as the errordocument URL-path.
Jim