如何使用 PHP 将之后/之后的所有内容保存到变量中?



目前我有一个用PHP制作的代理,它的工作原理如下:https://proxyurl/url=但我想摆脱url=,只是把网址放在斜杠后面。然后我想将斜杠后输入的所有内容保存到 PHP 内部的$url变量中。我将如何做到这一点?

我当前的代码:

<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
$url = $_GET['url'];
$ch = curl_init();
//Set the URL that you want to GET by using the CURLOPT_URL option.
curl_setopt($ch, CURLOPT_URL, $url);
//Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Execute the request.
$response = curl_exec($ch);
//Close the cURL handle.
curl_close($ch);
echo $response;
?>

例如:https://proxyurl/https://google.com- 其中https://google.com$url

https://proxyurl/google.comgoogle.com$url

我猜你正在使用更像这样的东西:https://proxyurl/?url=google.com.您不必对 php 代码进行任何更改。

正如elMeroMero所说,你需要在任何Apache配置文件中使用mode_rewrite。您可以将其与根目录中的 .htaccess 文件一起使用。你必须有这样的东西:

RewriteEngine On
RewriteRule (.*) ?url=$1 [L]

我不是mode_rewrite专家,也许其他人会修改我的建议。

最新更新