我如何在php中使用查询字符串重定向动态URL?

时间:2016-08-22 06:35:27

标签: php

我需要重定向这样的动态网址" https://test.com?user=abc@gmail.com"到" https://test.com"

2 个答案:

答案 0 :(得分:0)

如果我理解正确,此URL将动态显示查询字符串。并且您想要删除查询字符串部分并重定向到此修改后的URL。

我们假设动态网址存储在变量$ url。

试试这个:

$url = "https://test.com?user=abc@gmail.com";
$modified_url = strstr($url, "?", true); // Remove the query string, which results in https://test.com

header("location:".$modified_url);  // Redirect to the modified URL.

答案 1 :(得分:0)

您可以将动态部分存储在变量中,并使用header()功能重定向您的用户。

$dynamicPart = "someguy@somedomain.com";
header("Location: https://test.com/index.php?username=".$dynamicPart);
exit;