8

Is it valid and safe to use the parent directory double-dots inside an URL like in the following example:

http://example.com/path/../to/file.jpg

2
  • Why would you do that ?
    – t.m.adam
    May 10, 2017 at 16:02
  • 2
    Because you can get an URL by combine the base URL of a document with a relative path. e.g. var url = base_url + relative_path
    – Karsten
    May 11, 2017 at 6:31

2 Answers 2

11

RFC3986 defines URIs.

It describes how paths are hierarchical, and how...

The path segments "." and "..", also known as dot-segments

... work in a similar way to filesystem paths.

It also describes rules for "relative resolution" in which . and .. may be removed.

Essentially, it is legal and does what you expect.

1
  • You are right, how to remove dot segments is part of the standard. Section 5.2.4 Remove Dot Segments describes it exactly. So I can use this kind of „weird looking“ URL in my scripts. Thanks!
    – Karsten
    May 11, 2017 at 6:27
2

Yes it absolutely works. Just notice that the URL will change so the dots won't be displayed inside it. Like if you do http://path/to/new/../file the displayed URL will be http://path/to/file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.