I've looked around the web for this before, and I suspect the answer is "you can't", but since I've not yet found an answer which is that definitive, I think it's worth asking here. The closest I've found touching on the problem is The mystery of the trailing slash and the relative url (which is currently down, but Google has a text-only cached version).
Because of the traditional design of URLs with a trailing slash being interpreted as a directory and those without a trailing slash being interpreted as a file resource, and relative URLs working off the directory, then if the current page has a path of
/lorem/ipsum/dolor
a relative path of
not-dolor
will resolve as
/lorem/ipsum/not-dolor
which naturally makes sense, when /lorem/ipsum/dolor
is viewed as a file resource, dolor
, sitting in a directory, /lorem/ipsum/
; typical, intuitive conventions. However, since a significant number of websites are now dynamic applications without a filesystem mapping for each URL, this can cause headaches, because sometimes you really want to work relative to the path as though, in the current design, there were a trailing slash.
Is there any reasonable way ("not involving server-side processing/variables/other, or JavaScript") of using a relative path based off the current path, and not the "directory" of the current path? So that not-dolor
could be relative to /lorem/ipsum/dolor
and produce
/lorem/ipsum/dolor/not-dolor
There is no workaround that I know of involving something like ./not-dolor
, since .
is still (/lorem/)ipsum/
. Short of redirecting to a trailing slash and making sure that all resources have URLs which correspond to a directory-ish and a file-ish nature, or modifying the spec(!), is there any way of tackling this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…