Root-relative URL doesn't work locally

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

Root-relative URL doesn't work locally

Postby FrankC » 22. May 2018 18:24

Hi,

A link like
Code: Select all
<script src="/x-files/pretext-script.js"></script>
works fine on the remote server, but on the local server I get a 404:
Code: Select all
Loading failed for the <script> with source “http://localhost/x-files/pretext-script.js”


The latter location is indeed not where the x-files folder is at (it is at C:\xampp\htdocs\www\Websites\NameOfWebsite\), but I would like to use the root-relative URL (the leading slash). Is there a XAMPP setting that I can change so that I can? Or does a newer XAMPP version solve this problem?
FrankC
 
Posts: 39
Joined: 23. October 2011 03:57
Location: The city of cities
XAMPP version: 7.2.5
Operating System: Win 7 Pro 64-b

Re: Root-relative URL doesn't work locally

Postby Altrea » 22. May 2018 19:20

Hi,

What is the DocumentRoot of localhost?
urls starting with a slash (/) are always based on the DocumentRoot used for that request.
This is unrelated of the XAMPP version.
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: 9264
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Root-relative URL doesn't work locally

Postby Nobbie » 22. May 2018 21:02

FrankC wrote: Is there a XAMPP setting that I can change so that I can?


Of course there is no "XAMPP setting", as XAMPP is only a distribution, not a software.

But there maybe an Apache setting which helps you out of that, probably "ALIAS" might solve your problem. I really wonder that you are still struggeling with very basic Apache knowlegde, after so many years? Why is that? Dont you ever read any documentation, or what is wrong? I really cant get it, i have become a real "professional" in all these years and definately started from scratch without any knowlegde about Apache, PHP and MySQL. And its definately not because i am a genious (i wish i were), far from honestly. Simply reading documentation and trying out. You joined 7(!!!) years ago and you are still asking low level beginner questions. Very weird.
Nobbie
 
Posts: 10448
Joined: 09. March 2008 13:04

Re: Root-relative URL doesn't work locally

Postby FrankC » 23. May 2018 01:20

Altrea wrote:What is the DocumentRoot of localhost?

That's C:\xampp\htdocs\www\Websites\NameOfWebsite\ .

Nobbie wrote:You joined 7(!!!) years ago and you are still asking low level beginner questions. Very weird.

Because I have never needed root-relative URLs before. I always managed with file-relative URLs, which do work on both the remote and local server. And may I say that I do not exactly feel like an appreciated XAMPP user by your comment.
FrankC
 
Posts: 39
Joined: 23. October 2011 03:57
Location: The city of cities
XAMPP version: 7.2.5
Operating System: Win 7 Pro 64-b

Re: Root-relative URL doesn't work locally

Postby steve_t » 25. May 2018 08:39

One solution is to use Apache virtual hosts. For the AF pre-provided info on Apache virtual hosts, see XAMPP Dashboard | HOW-TO Guides | Configure Virtual Hosts.

Using root relative paths means you only have to provide the path (with leading slash) after the root of the web server. For XAMPP, the root of the Apache web server is C:/xampp/htdocs/. However, in your local, the root your web site(s) are C:/xampp/htdocs/www/Websites/NameOfWebsite/, which is not the root of the XAMPP Apache web server, which is why your root relative paths are not working locally.

In short, to use Apache virtual hosts as solution, in the Apache httpd-vhosts.conf file, copy one of the <VirtualHost *:80></VirtualHost> sections, make sure it is not commented out, and (in your case) set DocumentRoot to "C:/xampp/htdocs/www/Websites/NameOfWebsite/", which indicates the path to use as root relative path. Then set ServerName to http://www.websitedomain.com, which indicates the domain name to "register" to the DocumentRoot. Lastly, in the Windows\System32\drivers\etc\hosts file, add line 127.0.0.1 http://www.websitedomain.com and make sure it is not commented out. This DNSs/resolves the domain name entered into the web browser to 127.0.0.1/localhost. If necessary, restart XAMPP Apache to use new httpd-vhosts.conf, and restart web browser to use new hosts file.

Play around with virtual hosts. It works. Moreover, it scales to use one XAMPP installation to support the development of multiple web sites locally as follows. In the Apache httpd-vhosts.conf file, register each root relative path to its domain name (all uncommented out). In the Windows hosts file, DNS/resolve each domain name to 127.0.0.1/localhost, all commented out except the one that you want to use currently/presently locally. Please re-read that last line. Again, if necessary, restart XAMPP Apache to use new httpd-vhosts.conf, and restart web browser to use new hosts file.

Hope it helps.

Steve
steve_t
 
Posts: 15
Joined: 18. December 2014 04:28
XAMPP version: 5.6.24
Operating System: Windows Vista/7/8.1/10

Re: Root-relative URL doesn't work locally

Postby Altrea » 25. May 2018 09:01

FrankC wrote:
Altrea wrote:What is the DocumentRoot of localhost?

That's C:\xampp\htdocs\www\Websites\NameOfWebsite\ .

Okay, and what is the full path of the file /x-files/pretext-script.js?
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: 9264
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Root-relative URL doesn't work locally

Postby FrankC » 25. May 2018 11:46

@Steve -- I figured as much, that it would be a matter of creating virtual hosts (VH). But does that creation process really have to be that tricky? Installing Wordpress is even easier, with Bitnamy. And the How To describes a VH for one Wordpress site, while I have multiple normal sites. Also, the How To guide is well hidden. A beginner will never find it.

I'd think it would be a great selling point if AF would (semi-)automate the creation process. At least the documentation should cover multiple normal sites and be easier to find.
FrankC
 
Posts: 39
Joined: 23. October 2011 03:57
Location: The city of cities
XAMPP version: 7.2.5
Operating System: Win 7 Pro 64-b

Sorry, in post above, phpBB converted domain names to URLs

Postby steve_t » 26. May 2018 05:15

Sorry, in post above, phpBB default converts domain names (correct) to URLs (incorrect). The corrected sentences are below:

Then set ServerName to www.websitedomain.com, which indicates the domain name to "register" to the DocumentRoot. Lastly, in the Windows\System32\drivers\etc\hosts file, add line 127.0.0.1 www.websitedomain.com and make sure it is not commented out.
steve_t
 
Posts: 15
Joined: 18. December 2014 04:28
XAMPP version: 5.6.24
Operating System: Windows Vista/7/8.1/10

Re: Root-relative URL doesn't work locally

Postby steve_t » 26. May 2018 05:45

FrankC wrote:But does that creation process really have to be that tricky? Installing Wordpress is even easier, with Bitnamy. And the How To describes a VH for one Wordpress site, while I have multiple normal sites. Also, the How To guide is well hidden. A beginner will never find it.

I'd think it would be a great selling point if AF would (semi-)automate the creation process. At least the documentation should cover multiple normal sites and be easier to find.


If you think about it, how is the XAMPP Apache installer supposed to predict the DocumentRoot path that someone wants to use? Remember, the C:\xampp\htdocs directory does not even exist until after XAMPP is installed. So, configuring virtual hosts cannot be done by/built into the XAMPP Apache installer. Besides, configuring virtual hosts is simply editing two files. For the other concerns, the AF virtual hosts documentation seems sufficient, and sufficiently easy to find, to me.

Steve
steve_t
 
Posts: 15
Joined: 18. December 2014 04:28
XAMPP version: 5.6.24
Operating System: Windows Vista/7/8.1/10

Re: Root-relative URL doesn't work locally

Postby FrankC » 02. June 2018 01:36

Regarding the difficulties that arise when using test tablets and phones in combination with Virtual Hosts (viewtopic.php?f=16&t=77009), I'll just keep using file-relative URLs. Much easier for me, and my projects function well with them, too.
FrankC
 
Posts: 39
Joined: 23. October 2011 03:57
Location: The city of cities
XAMPP version: 7.2.5
Operating System: Win 7 Pro 64-b

Re: Root-relative URL doesn't work locally

Postby Nobbie » 02. June 2018 09:55

As the URLs do not provide different servers, VirtualHosts wouldnt solve that issue anyway. I still think that a simple ALIAS does the job, as i already mentioned above.
Nobbie
 
Posts: 10448
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 59 guests

cron