How to eliminate need for "localhost" prefix in Edge, localhosted site

Page 1 of 2 12 LastLast

  1. Posts : 7
    Windows 10 Pro
       #1

    How to eliminate need for "localhost" prefix in Edge, localhosted site


    Elsewhere in these forums it has been explained that for a localhost site to run in Edge, the Developer's Settings Use Microsoft Compatibility Lists and Allow Localhost Loopback should both be checked to be active. I have done that and I can use XAMPP for accessing the root of my localhost.

    However, there is a specific problem that hasn't been addressed, and one that prevents relative paths in my site to be accessed on Edge.

    First, please understand that my site runs in Edge when served from a live server. There's no problem there.

    Second, please understand that I can in fact get to the index.php of the main folder of my sites on localhost, but with one caveat, and that is the source of all of the other problems:

    --> In Edge, localhosted sites apparently (?) must be prefixed with 'localhost/' in order to be found and executed.

    This means that if I have a site called "mysite1", I cannot simply put "mysite1/" in the URL bar of Edge to access it. Instead, I must prefix it with 'localhost/', like this: "localhost/mysite1/". Then and only then will Edge find the index.php in the mysite1 folder and proceed.

    BUT: This means all relative path statements will not resolve correctly. For example, in my HTACCESS file, I have this MOD Rewrite directive:

    Code:
    RewriteRule ^info/?$ /info.php [L]

    This means that I can href info.php in the root of my site simply by using 'info'. However, because Edge insists on prefixing the URL with 'localhost/', a call to /info.php looks for it in the 'localhost/' directory, not the 'localhost/mysite1/' directory, and therefore it fails. This is also true for a simple HREF that calls '/index.php'. The only way around it is to put a dot before the slash, like this: './index.php'.

    I need to learn what configuration should be used to eliminate the need for prefixing localhosted sites with 'localhost/'

    All other browsers support my localhosted sites and serve them just by putting 'mysite1/', etc., in the URL bar. Edge seems to require a prefix of 'localhost/', thus 'localhost/mysite1'. I need to eliminate that requirement so that relative paths in my site code do not malfunction.

    I am using the current version of XAMPP.

    My C:\xampp\htdocs\ folder is shared with Administrator and with full permissions granted.


    In C:\Windows\System32\drivers\etc\hosts I have:


    Code:
    127.0.0.1       localhost
    127.0.0.1       mysite1
    127.0.0.1       mysite2
    etc.


    And in C:\xampp\apache\conf\extra\http-vhosts.conf I have:


    Code:
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost    
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/mysite1"
        ServerName mysite1
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/mysite2"
        ServerName mysite2
    </VirtualHost>
    etc.


    This allows me to run either localhost, mysite1, or mysite2 by putting in a browser's URL bar respectively (except in Edge):


    Code:
    localhost/
    mysite1/
    mysite2/
    This is my system setup and configuration, in case that is relevant. What settings do I need to apply to Edge in Windows 10 to eliminate the requirement for a prefix of 'localhost/' before the name of each of my localhosted sites?
    Last edited by TomXampp; 19 Oct 2015 at 18:09.
      My Computer


  2. Posts : 609
    W10
       #2

    Let me summarize:

    You have a website, which works correctly, if accessed through its URL, but which does not work, when you try to run it from your local PC when using Edge. This is a problem in Edge; it is working correctly with all other browsers.
    You have configured virtual hosts for localhost/ and for mysite1/. In Edge, you also can access the first by typing localhost/, but typing mysite1/ does not work.

    And that leaves me kind of clueless. Obviously this is not a problem in your website or in your virtual host configuration, but a problem in Edge.

    Is it maybe impossible to access other local sites than localhost/ with Edge? Would not be the first missing feature in that browser...
      My Computer


  3. Posts : 609
    W10
       #3

    Does Edge maybe have some kind of developer tools? Inspecting them might give you more information on what Edge thinks is going wrong. Some kind of error message would be great...
      My Computer


  4. Posts : 7
    Windows 10 Pro
    Thread Starter
       #4

    Joergi said:
    Does Edge maybe have some kind of developer tools? Inspecting them might give you more information on what Edge thinks is going wrong. Some kind of error message would be great...
    Your summary of my problem is accurate except for one detail: I can run localhost sites so long as I prefix their address with 'localhost', like this:

    Code:
    localhost\mysite\
    That works. This does not:

    Code:
    mysite\
    On all other browsers, I can access localhost sites just by putting the site name into the URL bar:

    Code:
    mysite\
    On Edge, a localhost site MUST be prefixed with 'localhost\', like this:

    Code:
    localhost\mysite\
    This causes a problem with relative paths. If I have a file in the root of mysite named info.php, I can access it anywhere in the site by an href of:

    Code:
    \info.php
    The initial slash take you to the root of the URL. On all other browsers, since the root is mysite\, '\info.php' accesses:

    Code:
    mysite\info.php
    ...because 'mysite\' is the root. However, because Edge by default requires that the URL be prefixed with 'localhost\', localhost becomes the root. Thus, an href to '\info.php' means the site code looks not to mysite\ but instead to 'localhost\', since 'localhost\' is the root of the URL. In other words, it looks for info.php here:

    Code:
    localhost\info.php
    And that's not where the info.php is kept. It's in 'mysite'. Therefore a 404 error is generated, for the file is not found when it is referenced with '\info.php'.

    If Edge did not require the URLs of localhosted sites to be prefixed with 'localhost\', this problem would vanish.

    It's important to understand that those same localhosted sites work perfectly in Edge when served from a live server, as 'mysite\', etc., is the defacto root in those cases.

    Please let me know if you need additional clarification.
      My Computer


  5. Posts : 609
    W10
       #5

    It surely is possible to adjust the Apache configuration in such a way that URLs requesting localhost/mysite1/ internally get rewritten to folder mysite1/. Possibilities might be mod_rewrite with RewriteRules or mod_alias with a Redirect. All that will only change the symptoms, but not the cause of the issue.

    In Insider Builds, prior to the release of Windows 10, Edge was unable to display local websites all together and it was a feature when Microsoft implemented support for localhost/.

    I have just done a small test on that and for me, it also does not work: It's OK with localhost, but not with other domains. I think Edge does not use the hosts file at all. Can you still see pages under localhost/, if you remove the localhost from the hosts file?
    Maybe using other local domains currently really is not possible.

    You could however configure Apache to listen on a different port for one of the sites. That way you could then access it using that port, e.g. as localhost:1234 (Not sure, if Edge supports that, but worth a try...)
      My Computer


  6. Posts : 7
    Windows 10 Pro
    Thread Starter
       #6

    I just realized a typo I made in the description of my httpd-vhosts.conf file. I neglected to add "htdocs" between "xampp" and "mysite1"/"mysite2" in the description of the file. I'm not sure if this has any bearing on your understanding of the problem and the responses you've provided, but just in case, I felt the need to report this oversight. Here's how the config file should appear.

    Code:
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost    
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/mysite1"
        ServerName mysite1
    </VirtualHost>
    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/mysite2"
        ServerName mysite2
    </VirtualHost>
    I've corrected this in the original posting.
    Last edited by TomXampp; 20 Oct 2015 at 15:14. Reason: "typo", not "type" in first sentence
      My Computer


  7. Posts : 609
    W10
       #7

    I see.

    Have you tried removing localhost from your hosts file? Can you still access files on localhost in Edge afterwards?
      My Computer


  8. Posts : 7
    Windows 10 Pro
    Thread Starter
       #8

    I have now tried doing that, but my sites won't work correctly unless the localhost is defined in both the Windows hosts file and in the XAMPP httpd-vhosts.conf file.
      My Computer


  9. Posts : 609
    W10
       #9

    Have you also tested that with Edge?
      My Computer


  10. Posts : 7
    Windows 10 Pro
    Thread Starter
       #10

    Of course, that's the browser that has the problem.

    Disabling the localhost identification in the httpd-vhosts.conf file of Apache in XAMPP prevents the site from running altogether. Specifically, I mean remming-out this code, like this:

    Code:
    #<VirtualHost *:80>
    #	 DocumentRoot "C:/xampp/htdocs"
    #     ServerName localhost    
    #</VirtualHost>
    Doing that prevents the site from running entirely. On the other hand, it's not necessary to rem-out the localhost definition in the Windows HOSTS file:

    Code:
    	127.0.0.1		localhost
    ...as that is handled by the DNS internally.

    So, there's that piece of the puzzle. And it remains a puzzle.

    The issue is simply that Edge requires locally-hosted sites to be prefixed by "localhost/" in their URL address. While that clarifies to the reader that the site is, in fact, coming from a localhost and not the web, it creates the potential for relative path confusion, as the root of each site must be spelled out to avoid confusion with the localhost/ root. (I hope that makes sense.)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 15:37.
Find Us




Windows 10 Forums