How to rewrite errordocument 404's with domain variable (Apache 1.3)

Folks,

For web server 'foo', I have in my httpd.conf

ErrorDocument 404 http://www.foo.com/404.html

Users will type 'http://www.foo.com/bogus_page.html', then Apache will redirect the request to 'http://www.foo.com/404.html'. But if users type 'http://www.bar.com/bogus_page.html', which has a DNS entry that resolves back to host 'foo', I want the ErrorDocument to redirect the request to 'http://www.bar.com/404.html" instead of "http://www.foo.com/404.html". Is there a way to do this?

There is some information on this from another document, as follows, but I'm not so sure this will work for us.

Thanks

http://articles.sitepoint.com/article/apache-mod_rewrite-examples/2

"
5. Redirecting to a 404 page if the directory and file do not exist

If your host doesn't provide for a "file not found" redirection, create it yourself!

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule .? /404.php [L]

Here, -f matches an existing filename and -d matches an existing directory name. This script checks to see that the requested filename is not an existing filename or directory name before it redirects to the 404.php script. You can extend this script: include the URI in a query string by adding ?url=$1 immediately after the URI:

RewriteRule ^/?(.*)$ /404.php?url=$1 [L]

This way, your 404.php script can do something with the requested URL: display it in a message, send it in an email alert, perform a search, and so on.
"
LVL 2
slicer123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slicer123Author Commented:
I have discovered a solution, see attached code snippet. Basically redirect the error document to a document on local server itself, then use rewrite cond and rule to capture the domain name and page, rewriting to appropriate destination server.
ErrorDocument 404 /bogus_page.html

RewriteCond %{HTTP_HOST} foo
RewriteRule bogus_page.html http://www.foo.com/404.html [L,R]

RewriteCond %{HTTP_HOST} bar
RewriteRule bogus_page.html http://www.bar.com/404.html [L,R]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.