Welcome to WebmasterWorld Guest from 188.8.131.52
ErrorDocument 404 / [R=301]
in hopes that this will tell the bots that the link they're checking (and which doesn't exist) has been moved to (the top page for the site).
What problems will this cause if any?
Search engine wise, I think it would be wiser to 301 each old page to its counterpart, rather than to the home page. Just my 2c, however.
BTW, I was just reading Shopping Carts 101 [webmasterworld.com]...Nice!
I'd suggest adding some explanatory (and apologetic) text, plus a text link to your home page on your custom 404-page, and also a 5-to-15 second meta-refresh redirect to your home page. This is a 302 redirect and so makes no implicit claim that the home page is a replacement for the custom error page or for the missing pages.
I've used that technique for years without ill effect in the search engines.
As Birdman says, it would be better to redirect each page to a close counterpart if one is available, and then use the method above for those that have no reasonable replacement.
You can minimize the number of code lines needed for the redirect by using the regex inline 'OR' function:
RewriteRule ^(file1¦file2¦file3¦file4)\.html$ http://www.example.com/newwidgets.html [R=301,L]
One last follow up. I mapped the missing pages and then added my 404 line:
ErrorDocument 404 /404.php
But the server chokes when I add this line. I've tried it immediately after the 'RewriteEngine on' and after my last mask (hiding dynamic pages) 'RewriteRule ^(.*)\.html$ $1.php [L] [T=application/x-httpd-php]'. When I first tested this without the additional mappings it worked. An idea as to why it's not working now?
ErrorDocument is an Apache 'core' directive, while Rewrite**** is a mod_rewrite directive. They are handled separately.
Also, look at your server error log to see what the problem was. You may need to add an AddHandler directive in order to parse php error pages if you *only* use that RewriteRule to redirect to php files, and do not reference them in any other way. In that case, you may not have a handler defined for php files, and any php file accesses (including ErroDocument) not done using the RewriteRule will not work.
This directive would take the form:
AddHandler server-parsed php
AddType application/x-httpd-php php
I think the issue is the wildcarded rules for *.htm and *.html which were designed to serve up php files. These rules seem to be taken before a 404 is detected (which makes sense). SO the test file foo.html initiates a rewrite to foo.php but foo.php does not exist. So the server delivers a generic 404 error. Seems like I may have to nail down the specific files I'm depending on the rewrite rule to handle in order to use the errordocument directive.
The process does indeed go as you have surmised, but the server should not deliver a 'generic' 404 error page, it should deliver your custom 404.php page. You are not redirecting 404.php, you are redirecting <anything>.html.
Is it possible that you have some other Redirect, RedirectMatch, or RewriteRule directives that are interfering?
RewriteRule ^(.*)\.htm$ $1.php [T=application/x-httpd-php]
RewriteRule ^(.*)\.html$ $1.php [L] [T=application/x-httpd-php]
I verified the 404.php file is there and have tried both a relative and absolute path.
RewriteRule ^(.*)\.htm[b]l?[/b]$ $1.php [T=application/x-httpd-php[b],L[/b]]
What kind of error are you getting?
re: errors. The bogus file I'm asking for - which I know doesn't exist - is foo.html.
The requested URL /foo.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Your ErrorDocument code is correct!
What happens of you request /404.php directly (from your browser address bar)?
If you're going crazy, be assured I'm going with you! :o
I entered the URI for the 404 page and got it - but with errors. Seems I forgot to remove the references to my development directory for things like the CSS, includes, and images.
Changed the paths on these and the file was delivered fine. Tested for foo.html and voila - the 404 page appears.
What do you make of that?