I'm developing a website which will live on https://www.example.com/
. While developing, and later as a test site, it's at http://127.0.0.1/temp-dir-for-my-project/
.
This means that I currently have a bunch of hrefs in the HTML, as well as CSS files, starting with /temp-dir-for-my-project/
, which obviously break once I'm done and upload it to the live site. Over there, it should be /
instead.
Sadly, the BASE
element, which I thought would solve this, only applies to relative paths. For example, ./meow.html
with /temp-dir-for-my-project/
as the BASE
would refer to /temp-dir-for-my-project/meow.html
, but /meow.html
in the same situation would be... /meow.html
, because it's an "absolute" path.
Before you say "just use relative paths, then!", well... If I do that, I have to keep track of in which "dir" I am. For example, for the webpage at https://www.example.com/test.html
, I could do: ./other.html
and it would work both on the live site and in my test site (assuming the BASE
is set). But the webpage at https://www.example.com/subdir/test.html
would have to link to './../other.html' or else it wouldn't link to the correct page.
This gets messy. I wish I could use "absolute" paths and still have the BASE
be the... base. Is there a way, or am I forced to use ./../../blabla...
for any page located in subdirs (whether those be real subdirs or just how the URL is rewritten to look)?
question from:
https://stackoverflow.com/questions/65894006/is-there-any-way-to-make-a-base-url-which-applies-even-if-hrefs-are-absolute 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…