apache - how to redirect page not found

Chris Howells howells at kde.org
Sun Oct 3 05:09:56 PDT 2004

On Sunday 03 October 2004 00:10, David Banning wrote:
> I notice on some web sites when you try to load a page that does not
> exist, it directs the users browser to another page. How do I set
> that up in apache?

If you have PHP installed, you can use the following PHP code:

 header("Location: http://www.newurl.com");

Of course this has the beauty that you can set up a PHP script as a 404 
handler, and if you know the old location of a page, then it is very trivial 
to automatically re-direct to this new location (since you know the path that 
was requested).

We use something like this on the KDE web site:



$handler = new Handler404();

where the 1st parameter to add() is the requested original URL, and the 2nd 
parameter is the URL to redirect to.

Cheers, Chris Howells -- chris at chrishowells.co.uk, howells at kde.org
Web: http://chrishowells.co.uk, PGP ID: 0x33795A2C
KDE/Qt/C++/PHP Developer: http://www.kde.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20041003/aadf9a93/attachment.bin

More information about the freebsd-questions mailing list