IN a situation like this, suck it and see, but there's no guarantee it'll work on all servers because they may be configured to redirect differently.
It's such a general problem, my guess is you're going to either have to spend a lot of time looking for a generic answer, or play about with a few variants, and put them in a compound if, and depending on the status (ie 404) try another tack.
Just another €0.02
Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)