views:

178

answers:

4

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?

A: 

its legitimate.

Just check if this works with IIS server. IMO it should. It does with Apache.

jrh

Here Be Wolves
thanks for bringing up iis. forgot I need to make sure of that too.
Andrew
wow. I love downvotes without reasons.
Here Be Wolves
Wasn't me, but could be because a question about links is purely an HTML question, regardless of the server. If anything, it should be checked cross-browser, not cross-server.
Kobi
hmm.. you're right.
Here Be Wolves
+1  A: 

I think it's fine.

Jonathan
+2  A: 

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.

Kobi
URLs are URLs, it works the same way as <a> elements, <img> elements, and any other element that takes a URL as a value to some attribute.
David Dorward
A: 

I think it's client side, so it should work with ASP.Net.

Malartre