Virtual Host Sites and Relative Addressing

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Virtual Host Sites and Relative Addressing

Postby billbell52 » 02. February 2015 16:26

Setup
Windows 7 and xampp-win32-5.6.3-0-VC11-installer.exe

I am new to Apache. I am using it in a small business environment as an internal server. I am able to do stuff that I could not do in IIS. I have an issue with virtual hosts and relative addressing. With none virtual host directories (C:\sites\sites1 and C:\sites\sites2). DocumentRoot is C:\sites. I have a page in each directory that has a relative link to the other page. The links work as expected and I move back and forth between pages.

Code: Select all
****** C:\sites\site1\site1.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Site 1</title>
</head>
<body>
    <h1>Site 1</h1>
    <a href="../site2/site2.html">Site 2</a>

</body>
</html>

****** C:\sites\site2\site2.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Site 2</title>
</head>
<body>
    <h1>Site 2</h1>
    <a href="../site1/site1.html">Site 1</a>

</body>
</html>



Now if I create 2 virtual host sites (C:\sites\vsite1 and C:\sites\vsite2) and place the same pages in the virtual host sites with the link modified it does not work. It puts the virtual host name at the front of the link so I can't get between virtual sites. I want to share CSS and Javascript files between virtual host sites and I want to use relative links. Is this some security measure that I can disable? Other than this virtual hosts works perfectly.

Code: Select all
****** C:\sites\vsite2\site1.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Site 1</title>
</head>
<body>
    <h1>Site 1</h1>
    <a href="../vsite2/site2.html">Site 2</a>

</body>
</html>

****** C:\sites\vsite2\site2.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Site 2</title>
</head>
<body>
    <h1>Site 2</h1>
    <a href="../vsite1/site1.html">Site 1</a>

</body>
</html>
billbell52
 
Posts: 5
Joined: 01. February 2015 18:16
Operating System: Windows 7

Re: Virtual Host Sites and Relative Addressing

Postby Nobbie » 02. February 2015 18:14

What are the DocumentRoots of the two VirtualHosts? If these are c:/sites/vsite1 and c:/sites/vsite2, it cannot work. Its not a security thing, it is missing understanding. There is no ".." if you are in a top level DocumentRoot. The Hostname (Domain), no matter if is a VirtualHost or Standard Host, is always prepended by the browser, because it is part of the URL.

You can only switch if you give the same DocumentRoot to both VirtualHosts.
Nobbie
 
Posts: 8780
Joined: 09. March 2008 13:04

Re: Virtual Host Sites and Relative Addressing

Postby billbell52 » 02. February 2015 19:11

Nobie, thanks. That makes perfect sense. I need to rethink how I want it to work.
billbell52
 
Posts: 5
Joined: 01. February 2015 18:16
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 32 guests