How can I reference a relative subdomain in HTML?

Say I have a website that is accessed by several domains, for example. domain1.com and domain2.com .

If I have a relative link, for example href="/wiki" , then no matter what domain name I get on the website, this link will lead me to the right place.

Say I wanted to use wiki.domain1.com and wiki.domain2.com , can I somehow link to this relative domain with the domain name?

If not, is there an elegant way to handle the link, such as the wiki link above, when multiple domains point to the same server?

+8
html subdomain hyperlink
source share
2 answers

Not. You will need to provide the entire domain. For a link from domain1.com to wiki.domain1.com link should look like href="http://wiki.domain1.com" .

+8
source share

This is not possible with relative paths, because the subdomain is actually a completely different area.

If you really cannot use the absolute URL, but can use PHP, you can 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 to a file, for example. imgproxy.php, and then you can link the images to another subdomain as follows:

 <img src="imgproxy.php?url=images/logo.png"> 
+4
source share

All Articles