How can I refer to a relative subdomain in HTML?

孤街醉人 提交于 2019-11-29 13:39:11

No. You'll have to give the whole domain. To link from domain1.com to wiki.domain1.com, the link has to look like href="http://wiki.domain1.com".

It is not possible with relative paths, because subdomain is in fact a whole different domain.

If you really can't use absolute URL, but can use PHP, you could try this proxy script:

<?php

if(!isset($_GET['url'])) {
    die('Missing URL!');
}

$subdomain_url = 'http://subdomain.example.com/';
$file_path = $_GET['url'];

$file_url = $subdomain_url . $file_path;

$mime = finfo_open(FILEINFO_MIME, $file_url);


header('Content-Type: ' . $mime);
header('Content-Transfer-Encoding: Binary'); 
header('Content-disposition: inline; filename="' . basename($file_path) . '"'); 

readfile($file_url);

Save it into a file, eg. imgproxy.php, and then you can link images on the other subdomain like this:

<img src="imgproxy.php?url=images/logo.png">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!