[Techtalk] redirect php 404 errors

Ben Knowles adric at adric.net
Wed Oct 24 22:37:58 UTC 2007


Hi,

Yes you can do this pretty easily with apache mod_rewrite rules (or
similar features in lighttpd).
Here's a very simple example which may demonstrate what you need:

#in a file called .htaccess or in any other apache container
(virtualhost, config file):
RewriteEngine on
RewriteRule ^alice.html$ bob.html

Which just does:
(turn on Mod Rewrite)
(for all incoming requests that match 'string starts, has exactly
"alice.html", and ends' send them to bob.html instead)

Rewrite rules use regular expressions, can mess with any aspect of a web
request (frequently they filter on referrers or request) and can be
really complex and arcane. There are some docs at
apache.org, eg http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
and lots of stuff in Google including a nice cheat sheet here:
http://www.ilovejackdaniels.com/cheat-sheets/mod_rewrite-cheat-sheet/.

Hope that helps, and wasn't too confusing :)
adric

Maria McKinley wrote:
> Thanks, that was very interesting. Apparently quite a few sites were 
> directing people to my scp instructions. It seems simple to get rid of 
> pages, but is there a simple way to redirect to the new pages? Either 
> through google, or on my own site?
>
> cheers,
> maria



More information about the Techtalk mailing list