You'd either need for the pervious link to communicate where it came from (http://redirects.com?src=original-site.com) or check the "referer" (request.env.http_referer)(not foolproof).
If it's just one file with hardcoded URLs, PHP is probably fine. Web2py does not require the use of a database.