我正在尝试创建一个脚本,根据输入的 URL 将用户重定向到不同的 URL。
例如:
test.foo.com/1234 重定向到 a.b.com/abc/def?info=1234
或
test.foo.com/9999 重定向到 a.b.com/abc/def?info=9999
最简单的方法是什么?
谢谢!
最佳答案
使用它在您的 php 脚本中提取请求的页面。
$_SERVER['REQUEST_URI']
然后执行此操作以重定向用户
header("Location: <a href="http://www.abc.com/" rel="noreferrer noopener nofollow">http://www.abc.com/</a>");
例子:
<?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;
?>
关于php - 根据输入的 URL 重定向到不同的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5241545/