我正在尝试配置一个索引文件,因为所有内容都在不同的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-urlencodedrn",
'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等)
但似乎没有人做我想做的事。。。
有没有什么方法可以在不必为我调用的每个文件定义绝对路径的情况下更改路径?
编辑
如果我缺乏知识,请告诉我,我渴望了解这个过程是如何运作的。
查看HTML的<base>
-标记。它为文档中的所有相对路径设置基本URL。
<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>
点击此处阅读更多信息:http://www.w3schools.com/tags/tag_base.asp
注意:这将设置所有相对路径以使用该基本URL(链接和所有内容)。