gpt4 book ai didi

php - 更改 HTML 源文件相对路径的 src 路径

转载 作者:行者123 更新时间:2023-12-02 21:08:43 27 4
gpt4 key购买 nike

我正在尝试配置一个索引文件,所有内容都会在不同的 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 中尝试了以下操作:

  1. set_include_path(' http://int.abayo.nl ');

  2. 更改 $_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(链接和所有内容)。

关于php - 更改 HTML 源文件相对路径的 src 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com