简体   繁体   English

根据输入的URL重定向到其他网页

[英]Redirect to different webpage based on URL entered

I am trying to create a script to redirect users to a different URL based on the URL entered. 我正在尝试创建一个脚本,以根据输入的URL将用户重定向到其他URL。

Ex: 例如:

test.foo.com/1234 redirects to abcom/abc/def?info=1234 test.foo.com/1234重定向到abcom / abc / def?info = 1234

or 要么

test.foo.com/9999 redirects to abcom/abc/def?info=9999 test.foo.com/9999重定向到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. 使用它来提取您的PHP脚本中的请求页面。

$_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. 您可以使用HTACCESS来达到最大效果。

RewriteEngine On 
RewriteRule ^(.*)$  http://a.b.com/abc/def?info=$1 [L] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM