Results 1 to 21 of 21

Thread: [RESOLVED] HTML sub directory problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Resolved [RESOLVED] HTML sub directory problem

    Having a problem with HTML sub directories. The browser indicates that it is operating in /dir2/subdir:
    view-source: http://localhost:8080/dir2/subdir

    The page source indicates that the file is located in /dir2/subdir:
    Code:
    <a href="dir2/subdir/Kitty.htm">Kitty.htm</a>
    Yet when the get request is issued by the browser, it repeats the first directory:
    Code:
    GET /dir2/dir2/subdir/Kitty.htm HTTP/1.1
    Does a browser keep track of directory movements?

    J.A. Coutts
    Last edited by dday9; Aug 2nd, 2021 at 10:49 AM.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    EspaƱa
    Posts
    506

    Re: HTML sub directory problem

    Code:
    <a href="/dir2/subdir/Kitty.htm">Kitty.htm</a>
    You have to put / before to be detected as the same domain
    Last edited by dday9; Aug 2nd, 2021 at 10:50 AM.

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    I think you have a big misconception of how paths work in URLs. URL paths have nothing and I mean absolutely nothing to do with directory paths. A URL actually has two components, the first part, which in your case is http://localhost:8080 is handled by a DNS or similar resolver to turn localhost into an IP address. The browser then uses that IP address and the port, 8080, to establish a connection to a web server at that IP address. Now the path, which in this case is dir2/subdir/, is entirely handled by the web server itself. The web server can interpret this path however it wants. It can be an actual directory or it could something entirely different.

    The real question I have here is what web server are you using to handle that request? If that web server if meant to interpret the paths in GET request as a directory location at it's location then it may not have been configured properly or you gave it the wrong path or something else along that line. Perhaps it might even be what the poster above suggested.

    What web server are you using?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Re: HTML sub directory problem

    Quote Originally Posted by Niya View Post
    I think you have a big misconception of how paths work in URLs. URL paths have nothing and I mean absolutely nothing to do with directory paths. A URL actually has two components, the first part, which in your case is http://localhost:8080 is handled by a DNS or similar resolver to turn localhost into an IP address. The browser then uses that IP address and the port, 8080, to establish a connection to a web server at that IP address. Now the path, which in this case is dir2/subdir/, is entirely handled by the web server itself. The web server can interpret this path however it wants. It can be an actual directory or it could something entirely different.

    The real question I have here is what web server are you using to handle that request? If that web server if meant to interpret the paths in GET request as a directory location at it's location then it may not have been configured properly or you gave it the wrong path or something else along that line. Perhaps it might even be what the poster above suggested.

    What web server are you using?
    I hate to burst your bubble, but URL paths are definitely tied to the server paths. The base path is defined within the server software, and is accessed via the IP address and domain name. When Gmail started blocking zipped executables, I would add the files to the "documents" sub directory, so that customers could access the files simply by adding /documents/filename.zip to the URL. That way, web crawlers could not find those files, only those people who were given specific directions.

    That worked until Google decided that they knew more than users by blocking those files (zipped or not) when downloaded through Chrome. Now I have to encode those files and instruct the customers on how to decode them. Google has become an extreme pain in the butt.

    I don't know who decided to move this thread, but it is directly related to the "Simplified Picture Server" post in the Visual Basic 6 and earlier CodeBank. I would ask the moderator to restore it to it's proper location.

    J.A. Coutts

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: HTML sub directory problem

    Quote Originally Posted by couttsj View Post
    I hate to burst your bubble, but URL paths are definitely tied to the server paths.
    No they aren't - they can be, but it depends on the server, as Niya mentioned:
    Quote Originally Posted by Niya View Post
    Now the path, which in this case is dir2/subdir/, is entirely handled by the web server itself. The web server can interpret this path however it wants. It can be an actual directory or it could something entirely different.

    While in one particular example you found that they seemed to be linked, that does not mean that all (or even most) web servers work the same way. With various web development technologies (I think MVC is one), the path is not related to directories at all, it is basically just a series of parameters (which could also be done use ? notation, but it is more readable with / instead).


    I don't know who decided to move this thread, but it is directly related to the "Simplified Picture Server" post in the Visual Basic 6 and earlier CodeBank. I would ask the moderator to restore it to it's proper location.
    While this thread might (to you) be related to a particular VB6 project, the question in this thread is in no way about VB6 - it is about unrelated web technology, so this forum is the right place for it (and is where you are most likely to get apt help).

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    Quote Originally Posted by couttsj View Post
    I hate to burst your bubble, but URL paths are definitely tied to the server paths.
    Writing web servers is a relatively simple affair in 2021. Here is a very simple one I wrote in VB.Net for .Net 5. If you look through the source code you will see EXACTLY how paths relate to web servers:-
    vbnet Code:
    1. Do
    2.             Dim context = listener.GetContext
    3.             Dim response As HttpListenerResponse = context.Response
    4.             Dim request = context.Request
    5.  
    6.             Select Case request.RawUrl.ToLower
    7.  
    8.  
    9.                  'Redirect to the home page
    10.                 Case "/"
    11.                     response.Redirect("/home")
    12.  
    13.  
    14.                 Case "/home"
    15.                     'Home page
    16.                     '******************************************
    17.                     visCount += 1
    18.  
    19.                     WriteWebPageResponse(GetHomePage(hostName, visCount), response)
    20.  
    21.                 Case "/info"
    22.                     'The info page that lists all network interfaces on the server machine
    23.                     '******************************************
    24.  
    25.                     WriteWebPageResponse(GetInfoHTML(), response)
    26.  
    27.                 Case "/img"
    28.                     'This path is used for the favicon.
    29.                     'This is the icon that shows up in the left side of
    30.                     'a web page's browser tab in the web browser.
    31.                     '******************************************
    32.  
    33.                     WriteImageResponse(My.Resources.LocalImages.favicon, response)
    34.  
    35.                 Case "/download/info"
    36.                     'This path is used to download a text file with the same
    37.                     'information shown in the info page.
    38.                     '******************************************
    39.                     WriteDownloadResponse(System.Text.Encoding.UTF8.
    40.                                          GetBytes(GetInfo()), $"{hostName}-info.txt", response)
    41.  
    42.                 Case "/download/picture"
    43.                     'This path triggers a download of an image file
    44.                     '******************************************
    45.  
    46.                     WriteDownloadResponse(My.Resources.LocalImages.Moon, "moon.jpg", response)
    47.  
    48.                 Case Else
    49.                     '404 Error. This happens when a request is made for a page
    50.                     'or resource from a path that doesn't exist.
    51.                     '******************************************
    52.  
    53.                     response.StatusCode = HttpStatusCode.NotFound
    54.                     WriteWebPageResponse(Get404HTML(), response)
    55.  
    56.  
    57.             End Select
    58.  
    59.             'Send reponse to web browser by closing the output stream
    60.             response.OutputStream.Close()
    61.         Loop

    This is how the home page is created:-
    vbnet Code:
    1. Private Function GetHomePage(ByVal hostName As String, ByVal visCount As Integer) As String
    2.         'This function generates the HTML for the home page.
    3.         '*********************************************************
    4.  
    5.         Dim sb As New StringBuilder
    6.  
    7.         sb.AppendLine("<HTML>")
    8.  
    9.         sb.AppendLine(GetFaviconHTML())
    10.  
    11.         sb.AppendLine($"<p>Hello from {hostName}!</p>")
    12.         sb.AppendLine($"<p>You are visitor number {visCount.ToString} to this site!</p>")
    13.  
    14.         sb.AppendLine(GetLinksHTML())
    15.  
    16.         sb.AppendLine("</HTML>")
    17.  
    18.         Return sb.ToString
    19.     End Function


    As you can see, URL paths have nothing to do with directory paths. In the case of my code above, it simply generates a web page on the go and which web page it generates is based on the path. As si_the_geek says above, a web server can interpret it as a directory path but that depends completely on the web server and how it's configured. No web server is under any obligation to treat a URL path as a directory path on it's file system. Real world web servers can do all kinds of wacky things with these paths. For example, NGINX uses URL paths as part of it's proxy implementation. It can act as a proxy server to another web server and a path is used to represent the web server it's acting as a proxy for. Nothing in this has anything to do with directories.

    That being said, most webservers do treat URL paths as directory paths under most normal conditions but you must understand what those conditions are. Sometimes it may need a bit of configuring and understanding how all of this really works can help you diagnose a lot of problems. This is why I asked what web server are you using.
    Last edited by Niya; Jul 31st, 2021 at 09:42 AM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Re: HTML sub directory problem

    All this discussion about web servers is interesting, but the problem I am dealing with is how the browser came up with the extra "dir2", and is this behavior to be expected from all browsers.

    J.A. Coutts

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

  9. #9
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: HTML sub directory problem

    Quote Originally Posted by couttsj View Post
    All this discussion about web servers is interesting, but the problem I am dealing with is how the browser came up with the extra "dir2", and is this behavior to be expected from all browsers.

    J.A. Coutts
    The browser wouldn't have come up with that path, the browser only knows what the server tells it. So presumably the server was either generating a href that included the extra "dir2" or the server is generating relative paths and the current url includes that "dir2"

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    Quote Originally Posted by couttsj View Post
    I don't know who decided to move this thread, but it is directly related to the "Simplified Picture Server" post in the Visual Basic 6 and earlier CodeBank. I would ask the moderator to restore it to it's proper location.
    You see, you should have mentioned this in your OP. This is why I kept asking what web server are you working with.

    I went ahead and downloaded that webserver from the CodeBank to try and reproduce the behavior you described in your OP and the requests work as I expected. However, there is a problem in that code. I'm not sure if you or someone else wrote that but there is a bug in how it translates URL paths to local directory paths:-
    vb6 Code:
    1. Private Function GetDirList(ByVal filePath As String, ByVal Directory As String) As String
    2.     Dim Dirs As New Collection
    3.     Dim Files As New Collection
    4.     Dim sDir As String
    5.     Dim HTML As String
    6.     Dim HTMLDir As String
    7.     Dim K As Long
    8.     Directory = Replace(Directory, "/", "")
    9.     If Right$(Directory, 1) <> "" Then Directory = Directory & ""
    10.     sDir = Dir(filePath & Directory, vbArchive + vbDirectory + vbReadOnly)
    11.     Do Until Len(sDir) = 0
    12.         If sDir <> ".." And sDir <> "." Then
    13.             If (GetAttr(filePath & Directory & sDir) And vbDirectory) = vbDirectory Then
    14.                 Dirs.Add sDir
    15.            Else
    16.                 Files.Add sDir
    17.             End If
    18.         End If
    19.         sDir = Dir
    20.     Loop
    21.     HTMLDir = Replace(Directory, "", "/")
    22.     HTML = "<html><body>"
    23.     If Dirs.Count > 0 Then
    24.         HTML = HTML & "<b>Directories:</b><br>"
    25.         For K = 1 To Dirs.Count
    26.             HTML = HTML & "<a href=""" & HTMLDir & Dirs(K) & """>" & Dirs(K) _
    27.                 & "</a><br>" & vbCrLf
    28.         Next K
    29.     End If
    30.     If Files.Count > 0 Then
    31.         HTML = HTML & "<br><b>Files:</b><br><table width=""100%"" border=""1"" cellpadding=""3"" cellspacing=""2"">" & vbCrLf
    32.         For K = 1 To Files.Count
    33.             HTML = HTML & "<tr>" & vbCrLf & "<td width=""100%""><a href=""" _
    34.                 & HTMLDir & Files(K) & """>" & Files(K) & "</a></td>" & vbCrLf _
    35.                 & "<td nowrap>" & Format(FileLen(filePath & Directory _
    36.                 & Files(K)) / 1024#, "###,###,###,##0") & " KBytes</td>" _
    37.                 & vbCrLf & "</tr>" & vbCrLf
    38.         Next K
    39.         HTML = HTML & "</table>" & vbCrLf
    40.     End If
    41.     If Dirs.Count = 0 And Files.Count = 0 Then
    42.         HTML = HTML & "This folder is empty."
    43.     End If
    44.     GetDirList = HTML & "</body></html>"
    45. End Function

    The above function does not work correctly when a multi-level path is specified in the browser. I sent this URL from my browser, http://localhost:8080/Level1/level2. I placed two pictures in my drive at the path D:\PICS\Level1\Level2. This eventually leads to a call to the above function where the filePath = D:\PICS, which is what I put in the settings , and Directory = /Level1/Level2. This is correct so far but the code after that which attempts to convert that URL path to a directory path produces D:\PICSLevel1level2\ which is incorrect. It should be D:\PICS\Level1\level2\

    I cannot say if that has anything to do with the problem you described since, as I said, the browser is sending the requests correctly but I get the feeling you're having some trouble with web server's handling of directory paths which means you should definitely be looking more carefully at how this function and any other like it are processing the paths from the GET requests.

    Also, what browser did you test this with when you got the problem described in your OP?
    Last edited by Niya; Jul 31st, 2021 at 11:38 AM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    I went ahead and changed this:-
    Code:
    Directory = Replace(Directory, "/", "")
    to this:-
    Code:
    Directory = Replace(Directory, "/", "\")
    And the web server works correctly with multi-level paths.
    Last edited by Niya; Jul 31st, 2021 at 12:02 PM. Reason: Fixed post. Forum doesn't allow backslashes in double quotes outside of code blocks.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: HTML sub directory problem

    I'm not following any of the posts that say the server has control over where an HREF points, excluding any redirecting the server might be doing, but that isn't in play here. Just plain old HTML 101, if you have a page on the following URL:

    Code:
    http://www.site.com/someSubdirectory/test/Index.htm
    and inside of that page are some HREF's exactly as below:

    Code:
    <A HREF="someSubdirectory/test/Hello.htm">1</A>
    <A HREF="test/Hello.htm">2</A>
    <A HREF="/someSubdirectory/test/Hello.htm">3</A>
    <A HREF="/test/Hello.htm">4</A>
    and you are trying to say that what web server is in use will dictate where the destination will be when these links are clicked, then..........

    I will have to remind you that when you hover over an HREF in a browser, the browser's status bar will tell you where it is going to direct you (excluding JavaScript overriding this...). And if you right-click that HREF and choose "Copy Link Location" or the like, it will copy the fully explicit "http://www.site.com/..." path that will be connected to when that link is clicked. And I trust you all understand that none of that activity (hovering over an HREF, or copying the destination of an HREF) has any "back and forth" interaction with the web server, so it can't possibly be involved in resolving an HREF to a full URL. It is all done by the browser.

    What is in play here:

    Using or not using a leading "/" in an HREF causes different destination URL's, as described in the URL I linked to earlier.
    The possibility of an explicit BASE HREF being used, which the OP hasn't stated either way.

    Edit: And Niya's findings. Nice catch!
    Last edited by OptionBase1; Jul 31st, 2021 at 11:38 AM.

  13. #13
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    I made a small video demonstrating the bug and a possible fix:-
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  14. #14
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: HTML sub directory problem

    Quote Originally Posted by OptionBase1 View Post
    I'm not following any of the posts that say the server has control over where an HREF points
    It isn't a matter of the server saying where the HREF points, it is the fact that any meaning to the path portion of a URL is entirely down to the server. Just because it looks like a directory path doesn't mean that is the case on the server. That is why knowing what is being used as a server / what the server application does is a very important question. The application or the web server could be doing entirely different things to what we think a URL means.

  15. #15
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: HTML sub directory problem

    Quote Originally Posted by PlausiblyDamp View Post
    It isn't a matter of the server saying where the HREF points, it is the fact that any meaning to the path portion of a URL is entirely down to the server. Just because it looks like a directory path doesn't mean that is the case on the server. That is why knowing what is being used as a server / what the server application does is a very important question. The application or the web server could be doing entirely different things to what we think a URL means.
    Of course, I'm in full agreement with that.
    Code:
    www.somesite.com/Folder/
    doesn't mean that on the web server that hosts that web page, there is a folder under the "web root" folder that is called Folder. There may not even be a "web root" folder, it could just all be being served from code, pulling pages content from a database, etc.

    But that isn't related to the initial question in any way.

    The first response nailed the reason. There needs to be a leading "/" in front of the HREF, and the reason is outlined in the answers given in the link I provided several posts above, and in those other answers are links to RFC's and the like that would likely explain exactly why in excruciating detail.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Re: HTML sub directory problem

    OK, I finally sorted this thing out. I redid the nested directory names to dir2, dir3, dir4, & dir5 to make it easier to follow. As several people tried to point out, the first "/" was missing on the HTML page. I just failed to see it, and the result was unexpected.

    Using default request:
    Get request from browser = /
    Page Source produced = <b>Directories:</b><br><a href="/dir2">dir2</a><br>

    Clicking on "dir2" link
    Get request from browser = /dir2
    Page Source produced = <b>Directories:</b><br><a href="/dir2/dir3">dir3</a><br>

    Clicking on "dir3" link
    Get request from browser = /dir2/dir3
    Page Source produced = <b>Directories:</b><br><a href="/dir2/dir3/dir4">dir4</a><br>

    Clicking on "dir4" link
    Get request from browser = /dir2/dir3/dir4
    Page Source produced = <b>Directories:</b><br><a href="/dir2/dir3/dir4/dir5">dir5</a><br>

    Clicking on "dir5" link
    Get request from browser = /dir2/dir3/dir4/dir5
    Page Source produced = <b>Directories:</b><br><a href="/dir2/dir3/dir4/dir5">dir5</a><br>

    Thanks to everyone that responded.

    J.A. Coutts
    Last edited by couttsj; Jul 31st, 2021 at 01:05 PM.

  17. #17
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    OK, let's try this again. I redid the nested directory names to dir2, dir3, dir4, & dir5 to make it easier to follow. These are actual results.

    Using default request:
    Get request from browser = /
    Page Source produced = <b>Directories:</b><br><a href="/dir2">dir2</a><br>

    Clicking on "dir2" link
    Get request from browser = /dir2
    Page Source produced = <b>Directories:</b><br><a href="dir2/dir3">dir3</a><br>

    Clicking on "dir3" link
    Get request from browser = /dir2/dir3
    Page Source produced = <b>Directories:</b><br><a href="dir2/dir3/dir4">dir4</a><br>

    Clicking on "dir4" link
    Get request from browser = /dir2/dir2/dir3/dir4
    corrected request = /dir2/dir3/dir4
    Page Source produced = <b>Directories:</b><br><a href="dir2/dir3/dir4/dir5">dir5</a><br>

    Clicking on "dir5" link
    Get request from browser = /dir2/dir2/dir3/dir2/dir3/dir4/dir5
    corrected request = /dir2/dir3/dir4/dir5
    Page Source produced = <b>Directories:</b><br><a href="dir2/dir3/dir4/dir5">dir5</a><br>

    J.A. Coutts
    I'm going to assume the web server you're talking about is the one you posted in the code bank. I just test EXACTLY what you just described using the same directory structure yet I'm not seeing the results you describe. This is the GET request from the browser when I click on dir4:-
    Code:
    GET /dir2/dir3/dir4 HTTP/1.1
    Host: localhost:8080
    Connection: keep-alive
    sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
    sec-ch-ua-mobile: ?0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    Sec-Fetch-Site: same-origin
    Sec-Fetch-Mode: navigate
    Sec-Fetch-User: ?1
    Sec-Fetch-Dest: document
    Referer: http://localhost:8080/dir2/dir3
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-US,en;q=0.9,es;q=0.8,bs;q=0.7
    Which is what I'd expect. It doesn't ask for dir2 twice as you said in your post. I tested this on Chrome and Edge and both browsers produced the correct behavior. What browser did you test this on?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  18. #18
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: HTML sub directory problem

    For the record, the testing I'm doing is with IE and FireFox. I don't have Chrome, but it is certainly possible that Chrome handles the presence or lack of the leading "/" in an HREF differently than other browsers.

  19. #19
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: HTML sub directory problem

    Quote Originally Posted by OptionBase1 View Post
    For the record, the testing I'm doing is with IE and FireFox. I don't have Chrome, but it is certainly possible that Chrome handles the presence or lack of the leading "/" in an HREF differently than other browsers.
    The problem he is describing is about the requests the browser is sending. He claims his browser when requesting a folder nested 3 or 4 levels deep, is requesting the folder at the first level twice. I've tried to reproduce this based on the description he provided in the post he deleted but it doesn't happen for me. My tests show that both Chrome and Edge are producing the correct HTTP GET requests for these nested folders.

    EDIT:

    To be honest, I'm kinda getting the impression that the web server he is writing might have a few bugs in it and he may be misdiagnosing a couple of these bugs. I seriously doubt all the top browsers right now would have such a serious flaw. Mismanaging GET requests is a very serious problem and they would fix that ASAP. Of course I can't make that claim with any kind of certainty until I test every single web browser with his web server and see if any of them produce the behavior he describes. It would be much easier if he just tells us which web browser he is testing this with.
    Last edited by Niya; Jul 31st, 2021 at 01:07 PM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  20. #20
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: [RESOLVED] HTML sub directory problem

    Here's what I'm testing with:

    Code:
    http://mysite/Test/Subdir/test.htm
    Desired URL to go to:

    Code:
    http://mysite/Test/Subdir/Hello.htm
    Contents of test.htm:

    Code:
    <HTML>
    
      <HEAD>
        <TITLE>Testing relative HREF's</TITLE>
      </HEAD>
    
      <BODY>
    
        <A HREF="Test/Subdir/Hello.htm">1</A> <br>
        <A HREF="Subdir/Hello.htm">2</A> <br>
        <A HREF="/Test/Subdir/Hello.htm">3</A> <br>
        <A HREF="/Subdir/Hello.htm">4</A> <br>
        <A HREF="../Subdir/Hello.htm">5</A> <br>
        <A HREF="/Hello.htm">6</A> <br>
        <A HREF="Hello.htm">7</A> <br>
    
      </BODY>
    
    </HTML>
    In order, these are the URL's that IE/Firefox will connect to when clicking these links:

    Code:
    http://mysite/test/subdir/Test/Subdir/Hello.htm (wrong)
    http://mysite/test/subdir/Subdir/Hello.htm (wrong)
    http://mysite/Test/Subdir/Hello.htm (correct)
    http://mysite/Subdir/Hello.htm (wrong)
    http://mysite/test/Subdir/Hello.htm (correct)
    http://mysite/Hello.htm (wrong)
    http://mysite/test/subdir/Hello.htm (correct)
    So without a leading "/", IE and FireFox append the complete HREF to the end of the current "base" path. (See numbers 1, 2, and 7)
    With a leading "/", IE and FireFox append the complete HREF path to the end of the "base" domain. (See numbers 4 and 6)

    After this further testing, my suggestion is that if you are serving content that is under the /dir2/ folder, then the simplest solution is to just eliminate any reference to dir2 in any HREF's, and use a relative HREF that doesn't have a leading "/" that references the next level of content below dir2. Or always use a leading "/" but make sure that the HREF then points to the entire path to the desired content as referenced from the root of your domain name.
    Last edited by OptionBase1; Jul 31st, 2021 at 01:17 PM.

  21. #21
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: [RESOLVED] HTML sub directory problem

    Ah, I get it now. This would be a bug in the code as I suspected. The web server may not producing the correct HREF links. Good catch!

    In any case. He should have more than enough info to fix this problem now.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width