views:

416

answers:

4

Hey guys, have a question regarding apache. I have a site that's been re-engineered, but I want to capture all the 'old' links that people may have bookmarked or come from search engines to the old site which is under a new domain name. How do I get apache to redirect only 404 not found to the old site?

TIA,

J

A: 

You could set your 404 document to a CGI that redirects the user.

 ErrorDocument 404 /cgi-bin/redirect-to-other.cgi
seth
+1  A: 

Another option, similar to that proposed by @seth is to add the handler so it points to a static html page which you can use to explain to the user what happen, and present them with options.

You can include a meta redirect so that if they don't do anything after a few seconds they're automatically redirected.

Which option will work best is really up to you do decide.

chris
+4  A: 

Your old domain should capture all responses and return a '301 moved permanently' response with the new domain in the 'Location' field of the header. A 404 means 'not found' and in this case it's not strictly true.

workmad3
That would work if I were redirecting to a new url, however it's the new site taking over the old url and the old site going to a different url. Putting a 301 moved permanently wouldn't work in this situation.
Jose Boveda
Ah, so you want 404 links on the new site to forward to the old site at the new domain... that makes sense but is different to how I understood your problem :)
workmad3
+2  A: 

You should first decide what status code you want to send. Sending both a 404 status code and a redirect is not possible.

But seth did already mention the right method, the ErrorDocument directive:

# local path
ErrorDocument 404 /local/path/to/error/document
# external URI
ErrorDocument 404 http://uri.example/to/error/document

If you use a local path, the 404 status code is sent. If you use an absolute URI, a 302 status code (temporary redirect) is sent.

And if you want to send a 301 redirect:

Redirect 301 / http://new.example.com/
Gumbo