0

Confusion in relative links

Suppose the file images.html is in the pictures folder, which is the subfolder of photos. Now, I have a file named index.html in the photos folder. In this file, I want to add a link, linking to images.html Now, which one is the correct link for images.html file- 1. <a href="/photos/pictures/images.html"> 2. <a href="/pictures/images.html"> Also, one more question, If I want to point a file located in the upper directory of the current directory, I use (../), so if I want to jump 2 or more directory above, then what will be the link? Thanks in advance!

29th Mar 2020, 3:49 AM
Himanshu Rai
Himanshu Rai - avatar
5 Antworten
+ 8
Depends from which folder you start the web server. if you started from a folder named photos. Then link will be relative to that folder "pictures/images.html" For jumping two or more directory listing above current you can chain ../ n number of times "../../../", Or provide full directory path to the target file. Of course, for better security it's better to limit access to current folder and a few subdirectories. Giving full file system access through your web server is not a good idea. Create a dedicated folder and limit acess to a few folders only.
29th Mar 2020, 4:03 AM
Lord Krishna
Lord Krishna - avatar
+ 7
Yes Himanshu Rai Edit: the file path should not start with "/" but "./" or the actual path "subfolder1/subfolder2/file.jpg" for relative paths. Here's an article discussing differences between relative vs absolute file paths: https://www.computernetworkingnotes.com/rhce-study-guide/differences-between-absolute-path-and-relative-path-in-linux.html
29th Mar 2020, 4:18 AM
Lord Krishna
Lord Krishna - avatar
+ 3
You using (../) for accessing upper directory is like that for to access further you can use (/folder/photos/pictures/images.html)
29th Mar 2020, 4:00 AM
Sudarshan Rai
Sudarshan Rai - avatar
0
Ok, got it!
29th Mar 2020, 4:20 AM
Himanshu Rai
Himanshu Rai - avatar
- 1
So if I want to point a file, located in a subfolder of the current folder, I don't need to mention the name of the current folder, I can start link URL with subfolder name, like: <a href="/subfolder/filename"> This link is relative to the location of the file, in which the link is present, so this is correct?
29th Mar 2020, 4:17 AM
Himanshu Rai
Himanshu Rai - avatar