In a question regarding a jQuery Ajax problem, the asker was trying to use a . in the beginning of a relative URL. I advised him to remove it, but have no idea what a dot actually does there.
His relative URL looked like this:
./delete-misc/test-ajax-code.php
I tried looking in the RFCs, without success. I know what the dot does in command line (either Linux or Win), it represents the current directory.
I'd like to know: how does this work on the Internet in a URL? Does it have any best-practice uses? Detailed explanations are most welcome.
The path segment . is typically used at the begin of relative path references and are removed during the reference resolution, i.e. the process of resolving a relative URI reference to an absolute URI:
The path segments "." and "..", also known as dot-segments, are
defined for relative reference within the path name hierarchy. They
are intended for use at the beginning of a relative-path reference
(Section 4.2) to indicate relative position within the hierarchical
tree of names. This is similar to their role within some operating
systems' file directory structures to indicate the current directory
and parent directory, respectively. However, unlike in a file
system, these dot-segments are only interpreted within the URI path
hierarchy and are removed as part of the resolution process (Section
5.2).
There is Remove Dot Segments algorithms that describes how these dot segments are to be interpreted in a certain base path context.
In your case both ./delete-misc/test-ajax-code.php and delete-misc/test-ajax-code.php are equivalent. But there are cases where a relative path can be misinterpreted as an absolute URI, e.g. having a : in the first path segment like search:foo that is different to ./search:foo as the former is an absolute URI while the latter is a relative URI path.
A ./ in front of the URL is equivalent to the current path. So ./delete-misc/test-ajax-code.php and delete-misc/text-ajax-code.php are both relative paths. In the answer you posted, you asked to remove the dot only, so the path of /delete-misc/test-ajax-code.php would translate as an absolute path instead of a relative path.
Edit: one more thing - . is the current directory and .. is the parent directory. As phihag comments, these really should be avoided and protected against in code. Directory traversal can be used for evil.
Now for a Simpler Explanation...
. and .. are NOT equivalent!
./ and ../ are NOT equivalent!
. and ./ ARE equivalent to
In all cases, . and ./ are the same as or "" or no path so not needed or used on the Web.
. (dot) is a relic of old UNIX pathing systems and NOT used on the World Wide Web for creating paths! Why? Because the dot in paths is redundant and equivalent to "" or no path or the current file directory you are in. The same result applies to using ./. It is the same as "" or no path. Both just reference the local directory your file is in ("./webpage.html" = "webpage.html").
What Path Should I Use?
So NEVER use . or ./ as both paths are irrelevant!
ALWAYS use ../ which is a RELATIVE PATH and says go up one folder.
ALWAYS use / which is an ABSOLUTE PATH and says starts from the website root folder.
Want More Proof?
Check out the result for these image paths. Assume you are referencing these paths from an HTML web page stored in the root of the web site:
SUCCESSFUL PATHS ("../" and "/" paths work well on the Web)
<img src="../images/photo.jpg" />
<img src="/images/photo.jpg" />
REDUNDANT PATHS ("." not needed)
<img src="/images/./photo.jpg" />
...same as...
<img src="/images/photo.jpg" />
<img src="/images./photo.jpg" />
...same as...
<img src="/images/photo.jpg" />
FAILED PATHS ("." in paths that fail on the Web)
<img src="/images/.photo.jpg" />
<img src="./images/photo.jpg" />
Related
In a file path, the set of "words" or folder names required to specify a specific file in a hierarchy of directories is called the path to the file, which is called path name. Path name can be either absolute or relative. In relative form, a sort of patterns like "./", "../", "../../", ... can be used to show the file/folder depth corresponding to the project base folder.
I know what they do or implying by behavior, but what are they called? Do they have a specific name? For example, what is called "../" or "..\" in a file system?
Briefly, it is called levelup notion.
Let's start with defining path:
A path is a slash-separated list of directory names followed by either
a directory name or a file name. A directory is the same as a folder.
Then, we look at types of paths: Absolute and relative paths!
An absolute, or full, path begins with a drive letter, whereas a relative path refers to a location that is relative to a current directory.
In relative paths we may use dot and double-dot symbols. A dot here means the current directory itself. And the double-dot notation, which is called level-up, is used for moving up in the hierarchy.
Now to change the directory using the dot notion we do as follows:
A single dot represents the current directory itself. for example:
in a command line interface (e.g. PowerShell):
cd . will not change the directory as itself point to the current directory.
To change the directory using the level-up notion we do as follows:
each double-dot notions takes you one level up, meaning one folder closer to the base drive or root folder in the hierarchy.
Look at the example below for different cases of using levelup notions:
For clarification, I'm just talking about relative file paths that also include a directory or filename in them, for example ../../some_directory/my_file.ext. I understand that ./ is current directory and ../ is parent directory and that on their own they are in fact relative paths.
But, I am wondering in the context of a relative path that includes directory/directories and possibly the filename and extension after the dots and slashes, what are the dots and slashes known as? The "directory referrer", "path adjuster", etc.?
I'd like to know, because I have a function that creates this portion of the relative path based on target folder's depth (which I am calling frequently throughout my app) and I'd like to give it a name that will help make my code more legible to others. Right now I'm calling them dotSlashes and the function is called prependDotSlashes.
I've googled and stackoverflowed around, but didn't find a definitive name.
If anybody knows the industry-standard name for this portion of relative file paths, I would be curious to know it.
Man, I know the dot as "current directory", and the slashes as directory separator.
The double dots (..) is know as parent directory.
Relative path is a path relative to where you are. Eg: If you are in the /etc path, then, the ./apache path is a relative to that /etc. A full string path (from the root) is named absolute path. So, for example:
../../../../ => Relative path
/home/user/Documents/doc1 => absolute path
./Document/doc1 => relative path from home
I'm working on a custom rule in skylark that is trying to use the proto compiler. Due to intricacies of how it works, I need to split a path into a directory for the external dependency and the path part that is relative to that.
Example1:
File:[/private/var/tmp/_bazel_endobson/c56b77af296477cd0f319aa9d4ce1d19[source]]external/googleapis/google/devtools/build/v1/build_status.proto
I want the paths:
/private/var/tmp/_bazel_endobson/c56b77af296477cd0f319aa9d4ce1d19/external/googleapis/
google/devtools/build/v1/build_status.proto
Example2:
File:[[/private/var/tmp/_bazel_endobson/c56b77af296477cd0f319aa9d4ce1d19/execroot/bes_example]bazel-out/darwin_x86_64-fastbuild/genfiles]external/com_google_protobuf/google/protobuf/any.proto
I want the paths:
/private/var/tmp/_bazel_endobson/c56b77af296477cd0f319aa9d4ce1d19/execroot/bes_example/bazel-out/darwin_x86_64-fastbuild/genfiles/external/com_google_protobuf
google/protobuf/any.proto
The issue is that bazel allows accessing the root and root relative parts of the path, but doesn't give insight into if the path has the 'external/' part or not. The protocol buffer compiler needs this because it needs to know the directories that correspond to the root directories from the user's point of view so that it can use relative paths from the source.
Is there a principled way of detecting this other than hackily looking at the path to see if it has 'external' in it?
I'm afraid I cannot give you a really great answer here :( Eventually, we'd like to remove the "external" path segment, but it hasn't happened yet. The current rule is that you have it for source artifacts, but you don't have it for generated artifacts.
Thus, what I'd do is exactly what you suggest -- check if the first path segment is "external".
I'm using the URL like web.com/sys/test, which is rewritten in nginx config to web.com?system=sys&id=test via rewrite ^/(\w+)/(\w+)$ /?system=$1&id=$2 break;.
Also, all my resource files have relative path.
Therefore I get error:
Unable to find web.com/sys/css/user.css, however user.css is located in /css/.
Is there a way to solve the problem remaining the relative path for resource files?
Used base tag:
<base href="/">
However, in some cases this method may just add a whole lot of new problems. Look at this link
I understand that an absolute path is of the type:
http://www.example.com/thisdir/4/5uy3/2/s.js
and also, that relative paths are of the type:
5uy3/2/s.js (in relation to directory "4")
but what is the term for the type of path that is prepended with a slash to reference back to the root? For example, if someone was working on a script in s.js, he/she might use /thisdir/4/5uy3/2/s.js when including that javascript from different directories to avoid having to consciously think about the current working directory when including it.
Do you know what this type of path is called?
From Dreamweaver / About linking and navigation
There are three types of link paths:
Absolute paths (such as http://www.adobe.com/support/dreamweaver/contents.html).
Document-relative paths (such as dreamweaver/contents.html).
Site root–relative paths (such as /support/dreamweaver/contents.html).
The term "application root" would be the same as "site root" except that the site must be an application.