I want to program a conditional rewrite in PHP which will be located in my header.php file that redirects the URL based on a condition such as the geo location or referrer. The part I don't know how to do is to redirect in the manner I would like. For example: A user tries to access the following fictional URL: www.domain.com/products/ but because the meet a certain condition, for example their geographical location I would want to redirect them to: www.domain.co.nz/products I want this to happen with one set of code for every page but it rewrites/redirects the page but only changes the top level domain (TLD) i.e .com to .co.nz Help would be very much appreciated.
okay if you have geo location script. you must have the script to tell country TLD. like for canada, .ca for USA, .us for australia, .au for Some country, .com suppose you have the geolocation tld on $tld now suppose $tld is .ca now write this thing in a new file called redirect.php : <?php $current_page = str_replace(".com", $tld, $_SERVER['PHP_SELF']); if ($tld != '.com') { header("Location: $current_page"); } ?> PHP: now on every page, on top of anything, write this code: <?php include_once ("Path-to-redirect.php"); ?> PHP: where the Path-to-redirect.php is the absolute path to file, i-e: "includes/redirect.php" This code will redirect the user to the TLD of their country, without changing the URL , for example : http://example.com/members/usercp/avatars.php --> http://example.co.uk/members/usercp/avatars.php The above action will only be performed if the user is not in a country whose TLD is .com (which you can assign in geo location script). For complete guide, read this : http://www.pegor.com/tutorials/php-mysql/redirecting-users-according-to-their-country-tld/ Hope this helps
Nastynappy (what a name!) that sounds like exactly what I want. I'll have to try it. That's amazing since I thought no one was gonna reply or maybe it couldn't be done. Thanks very much for your help.
My pleasure If you want more of these codings, request them on my website I will write them for you. my website is in my sig. Thankyou