Reputation: 238747
Sorry if this is a stupid question...
I've developed an application that creates absolute links by prepending urls with the site root (of whichever site it is hosted).
For example:
<link rel="stylesheet" href="<?=SITE_ROOT?>/assets/css/global.css">
Notice that a slash is coming after site root. I need to convert this now to be relative links, so I tried using a dot as the value of SITE_ROOT.
This creates this:
<link rel="stylesheet" href="./assets/css/global.css">
As far as I can tell, it works fine. Is this a legitimate relative link? Or is there a reason why I shouldn't do it this way?
Note: I'm not trying to go up a directory, otherwise I would use ../ I'm simply trying to stay in the same directory. Since there is a slash after SITE_ROOT, I can't leave it blank or it would become a root relative link.
Update: Will this work with IIS?
Upvotes: 2
Views: 529
Reputation: 138027
These links work on the client, not on the server, and as far as I know should behave the same as <a>
links. ./assets/css/global.css
is the same as assets/css/global.css
, meaning the folder assets under the current sub site. the ./
part is redundant.
If you what a link relative to the server you should start it with a slash, ie: /assets/css/global.css
will go to stackoverflow.com/assets/css/global.css
, even when you are on a sub site.
Upvotes: 4
Reputation: 26583
its legitimate.
Just check if this works with IIS server. IMO it should. It does with Apache.
jrh
Upvotes: 0