【发布时间】:2016-01-08 09:51:49
【问题描述】:
我正在尝试配置一个索引文件,其中所有内容都在不同的 URL 下生成,然后返回。
因为我的 HTML src 标签都有相对路径,所以内容自然会得到 404。
我请求的 URL:“ext.abayo.dev”,请求的 URL 的 index.php 是这样的:
$url = 'http://int.abayo.dev';
$data = array(
'customer' => 'customer_1',
'domain' => $_SERVER['HTTP_HOST'],
'license' => '1234656',
'uri' => $_SERVER['REQUEST_URI'],
'post_vars' => ''
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
print($result);
结果包含一个带有内容的模板,当然还有 CSS 和 JavaScript 文件,例如:
<script src="/dist/jquery-ui-1.11.4/external/jquery/jquery.js"></script>
绝对路径应该是:
http://int.abayo.dev/dist/jquery-ui-1.11.4/external/jquery/jquery.js
但是变成:
http://ext.abayo.dev/dist/jquery-ui-1.11.4/external/jquery/jquery.js
因为我的所有内容都在我的 int.abayo.dev 上,所以找不到内容。
-
我在 'ext.abayo.nl' index.php 中尝试了以下内容:
set_include_path('http://int.abayo.nl');
更改 $_SERVER 变量(HTTP_HOST、DOCUMENT_ROOT、SERVER_NAME 等)
但似乎没有人按照我的意愿行事......
有没有什么方法可以改变路径而不必为我调用的每个文件定义绝对路径?
编辑
如果我缺乏知识,请告诉我,我很想了解这个过程是如何运作的。
【问题讨论】:
-
set_include_path用于 PHP(在服务器上运行),与 HTML(在客户端运行)没有任何关系。