Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a relative url go one step back

I have a url: http://test.com/test1/test2/
Is there a way to make a relative url from test2 to test1? Like just one step back?
Without Javascript.
The /test1/ part may change, that’s why I need to go from /test/2 just one step back to /test1/ (or to a changed url)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can link with ../. Indeed, if you visit /test1/test2/ and the URL contains ../, it will move one directory up, so /test1/.

This is specified in RFC-3986 of the W3 organization [w3.org], in the Merge paths section [w3.org], and as section 3.3 on Paths [w3.org] describes:

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.

You thus can make a link to go to the "parent directory" that looks like:

<a href="../">parent<a>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading