【发布时间】:2020-04-16 07:02:53
【问题描述】:
目前我有一个用 PHP 制作的代理,它的工作原理如下:https://proxyurl/url= 但我想摆脱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.com,其中google.com 是$url
【问题讨论】:
-
您可以使用 .htaccess mod_rewrite 执行此操作,您可以在其中定义 proxyurl.com/www.google.com 等于 proxyurl.com/?url=www.google.com