PIDZB
PIDZB

Reputation: 913

Change src path of relative paths of HTML source files

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

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

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);

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>

The absolute path SHOULD be :

http://int.abayo.dev/dist/jquery-ui-1.11.4/external/jquery/jquery.js

But becomes:

http://ext.abayo.dev/dist/jquery-ui-1.11.4/external/jquery/jquery.js

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

-

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

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

  2. 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?


EDIT

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

Upvotes: 2

Views: 2241

Answers (1)

M. Eriksson
M. Eriksson

Reputation: 13635

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>

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

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

Upvotes: 5

Related Questions