Subdirectory as Root / Root Relative Path problem

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

Subdirectory as Root / Root Relative Path problem

Postby dw87 » 07. April 2014 14:19

I'm trying to get a local copy of a website configured on my machine, using XAMPP, but I'm finding the configuration impossible.

I put all the files into a subdirectory of localhost, and browse to it as expected with /localhost/subfolder.

This displays the content, but none of the URLs on the page are correct, and none of the CSS, JavaScript etc files work. These are all root relative through the entire site, and I am not going to edit hundreds of files to change these.

How can I configure XAMPP so that instead of URLs pointing to /localhost/page.php and CSS pointing to /localhost/style.css etc, they point correctly to /localhost/subfolder/page.php and /localhost/subfolder/style.css.

It strikes me as something that should be simple, straightforward and sensible to do. But as yet, I have found no way to do this.

I have tried configuring VirtualHosts, and using .htaccess rules, but nothing works.

I do not want to dump all the site files directly into /localhost. That does not seem like it should be the only solution.

Any help would be greatly appreciated, and apologies if this has been asked before. I have looked, but I didn't find anything that matched this problem.
dw87
 
Posts: 3
Joined: 07. April 2014 14:11
Operating System: Windows 8.1 (Unfortunately)

Re: Subdirectory as Root / Root Relative Path problem

Postby Nobbie » 07. April 2014 17:56

dw87 wrote:I have tried configuring VirtualHosts, and using .htaccess rules, but nothing works.


As you dont show what you did, we can say ... nothing!

Anyway, VirtualHosts should work, if correctly configured. Simply point the DocumentRoot of your VirtualHost to the full path of your project. And then dont call it via http://virtualhost/subfolder, but instead via http://virtualhost ("subfolder" is alread part of the DocumentRoot).
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Subdirectory as Root / Root Relative Path problem

Postby dw87 » 07. April 2014 20:15

Nobbie wrote:
dw87 wrote:I have tried configuring VirtualHosts, and using .htaccess rules, but nothing works.


As you dont show what you did, we can say ... nothing!

Anyway, VirtualHosts should work, if correctly configured. Simply point the DocumentRoot of your VirtualHost to the full path of your project. And then dont call it via http://virtualhost/subfolder, but instead via http://virtualhost ("subfolder" is alread part of the DocumentRoot).


Yeah, my bad, I've spent days trying different things it's been difficult keeping track of everything.

Ok, VirtualHosts should work, I will have another look at that and work out what I got wrong before. I found what I think is the correct hosts configuration in Windows, but the file was only comments and no configuration. Is localhost not configured there?

Surely this is overkill though? There must be an easier way to configure a subfolder inside /localhost that sees itself as root, not /localhost. I can see that root relative paths are fine for live servers, but for development environments, shouldn't there be a way to work with them under /localhost but keeping different websites in their own subfolders?
dw87
 
Posts: 3
Joined: 07. April 2014 14:11
Operating System: Windows 8.1 (Unfortunately)

Re: Subdirectory as Root / Root Relative Path problem

Postby Altrea » 07. April 2014 20:46

dw87 wrote:I can see that root relative paths are fine for live servers, but for development environments, shouldn't there be a way to work with them under /localhost but keeping different websites in their own subfolders?

Your scripts are relatively addresses to the root of your Domain. That is the case if your asset paths are beginning with a slash.
The only recommend way to go are virtual hosts.

With virtual hosts (e.g. namebased virtual hosts) you can define different DocumentRoot paths each with their own DomainName.
For example:

Code: Select all
C:/xampp/htdocs/                         <-- Documentroot of localhost
C:/xampp/htdocs/styles.css               <-- path /styles.css
C:/xampp/example.com/htdocs/             <-- DocumentRoot of example.com
C:/xampp/example.com/htdocs/styles.css   <-- path /styles.css
C:/xampp/test.dev/public_html/           <-- DocumehtRoot of test.dev
C:/xampp/test.dev/public_html/styles.css <-- path /styles.css
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Subdirectory as Root / Root Relative Path problem

Postby dw87 » 09. April 2014 10:37

Thanks for the help, VirtualHosts did solve the problem. I think when I first tried it there was a problem with my Windows hosts file that meant it didn't work. I've tried configuring everything again today and it's working as I need it to.

I still don't see why it should be this complicated to configure a subfolder of localhost to be it's own root directory, but never mind. It works, and that's what matters.
dw87
 
Posts: 3
Joined: 07. April 2014 14:11
Operating System: Windows 8.1 (Unfortunately)


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 157 guests

cron