I am trying to create a script to redirect users to a different URL based on the URL entered.
Ex:
test.foo.com/1234 redirects to abcom/abc/def?info=1234
or
test.foo.com/9999 redirects to abcom/abc/def?info=9999
What would be the easiest way to do this?
Thanks!
Use this to extract the requested page in your php script.
$_SERVER['REQUEST_URI']
Then do this to redirect the user
header("Location: http://www.abc.com/ ");
Example:
<?php
$request = $_SERVER['REQUEST_URI'];
$request = trim($request, '/');
//there can be no output before this line
header("Location: http://www.abc.com/def?info=".$request);
exit;
?>
You can use HTACCESS to do this most effectivley.
RewriteEngine On
RewriteRule ^(.*)$ http://a.b.com/abc/def?info=$1 [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.