更改HTML源文件的相对路径的src路径 [英] Change src path of relative paths of HTML source files

查看:90
本文介绍了更改HTML源文件的相对路径的src路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置索引文件,以使所有内容都在不同的URL下生成,然后提供给我们.

I am trying to configure an index file in that all the content gets generated under an different URL and then given back.

由于我的HTML src标签都具有相对路径,因此内容自然会得到404.

Because my HTML src tags all have relative paths, naturally the content gets a 404.

我请求URL:"ext.abayo.dev",所请求URL的index.php看起来像这样:

I request the URL: "ext.abayo.dev", the index.php of the URL requested looks like this:

$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文件,例如:

The result contains a template with content and of course CSS and JavaScript files such as:

<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上,所以找不到该内容.

Because all my content is on my int.abayo.dev, the content cannot be found.

我已经在'ext.abayo.nl'index.php中尝试了以下操作:

I've tried the following in the 'ext.abayo.nl' index.php:

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

更改$ _SERVER变量(HTTP_HOST,DOCUMENT_ROOT,SERVER_NAME等)

change $_SERVER variables (HTTP_HOST, DOCUMENT_ROOT, SERVER_NAME, etc)

但是似乎没有人做我想要的...

But none seem to do what I want...

有什么方法可以更改路径而不必为我调用的每个文件定义绝对路径吗?

Is there any way to change the path without having to define absolute paths for every file I call?

编辑

如果我缺乏知识,请告诉我,我很想了解此过程的工作原理.

If I lack knowledge, please tell me, I am eager to understand how this process works.

推荐答案

查看HTML的< base> -标记.它将为文档中所有相对路径设置基本URL.

Check out HTML's <base>-tag. It sets the base URL for all the relative paths in your document.

<head>
    <base href="http://www.w3schools.com/images/" target="_blank">
</head>

在此处了解更多信息: http://www.w3schools.com/tags/tag_base.asp

Read more here: http://www.w3schools.com/tags/tag_base.asp

注意:这将设置所有相对路径以使用该基本URL(链接和所有内容).

Note: This will set ALL relative paths to use that base URL (links and everything).

这篇关于更改HTML源文件的相对路径的src路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆