Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Oct 2004 13:09:48 +0100
From:      Chris Howells <howells@kde.org>
To:        freebsd-questions@freebsd.org
Cc:        David Banning <david+dated+1097190608.0a8a39@skytracker.ca>
Subject:   Re: apache - how to redirect page not found
Message-ID:  <200410031309.52491.howells@kde.org>
In-Reply-To: <20041002231007.GA80368@skytrackercanada.com>
References:  <20041002231007.GA80368@skytrackercanada.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
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:

<?php
 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:

http://webcvs.kde.org/cgi-bin/cvsweb.cgi/www/media/includes/classes/class_handler404.inc?rev=1.4

e.g.

<?php
include("handler.inc");
$handler = new Handler404();
$handler->add("/anoncvs.html","http://developer.kde.org/source/anoncvs.html");
$handler->add("/family.html","/family/");
?>

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@chrishowells.co.uk, howells@kde.org
Web: http://chrishowells.co.uk, PGP ID: 0x33795A2C
KDE/Qt/C++/PHP Developer: http://www.kde.org

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQBBX+wQF8Iu1zN5WiwRAr7DAKCPXqAMhfFlG9bMtPbH0bbg2ZdFdgCeJuBY
+AuAa0INShkxn0RdI7jSuSM=
=DsPZ
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410031309.52491.howells>