Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > stylesheet now seen under some conditions without "/". Convention?

Reply
Thread Tools

stylesheet now seen under some conditions without "/". Convention?

 
 
mscir
Guest
Posts: n/a
 
      10-11-2004
I have a question I'm hoping someone here can answer.

I customized a 403.html page on a site so if people tried to access
protected folders they would see that page and still be able to navigate
the site, the generic 403 error page provided by the host was too boring
and provided no explanation or site navigation.

All of the pages on the site use an external stylesheet, I placed this
line in the head section of each page:

<link href="styles.css" type="text/css" rel="stylesheet">

All web pages are in one folder, styles.css is in the same folder. The
site works great except I ran into an interesting problem:

I created a protected sub-folder "/archive" under the folder the site
files reside in. Then I testd whether the 403.html page I made would
show up correctly if I tried to access the protected folder from my
browser (not loggin in with an FTP program) as a public user. If I tried
to access the folder like this I saw the 403 page correctly:

url/archive

But if I tried to access the folder like this (with an ending slash) I
saw the page I made without the styles in the stylesheet applied:

url/archive/

To fix it, the site host suggested I add a slash before the stylesheet
name. When I did that the styles were applied correctly in both cases!

<link href="/styles.css" type="text/css" rel="stylesheet">

Can any body explain that? Is it always recommended that a slash is
always used to represent the relative url before a stylesheet name -
even if it's in the same folder as the pages that reference it? Is it
better to always name the absolute url of the stylesheet? I'm wondering
if there's a convention, or recommended policy.

Thanks,
Mike



 
Reply With Quote
 
 
 
 
brucie
Guest
Posts: n/a
 
      10-11-2004
In alt.html mscir said:

> <link href="styles.css"


styles.css is in same directory as file that uses it.

> <link href="/styles.css"


styles.css is in the root directory.



--


v o i c e s
 
Reply With Quote
 
 
 
 
Michael Fesser
Guest
Posts: n/a
 
      10-11-2004
.oO(mscir)

>I created a protected sub-folder "/archive" under the folder the site
>files reside in. Then I testd whether the 403.html page I made would
>show up correctly if I tried to access the protected folder from my
>browser (not loggin in with an FTP program) as a public user. If I tried
>to access the folder like this I saw the 403 page correctly:
>
>url/archive
>
>But if I tried to access the folder like this (with an ending slash) I
>saw the page I made without the styles in the stylesheet applied:
>
>url/archive/
>
>To fix it, the site host suggested I add a slash before the stylesheet
>name. When I did that the styles were applied correctly in both cases!
>
><link href="/styles.css" type="text/css" rel="stylesheet">
>
>Can any body explain that? [...]


In case of an 403/404/... the response from the server contains the
content of the error page, not a redirect or something like that. So the
browser displays the received content under the URL that caused the
error and will use that(!) URL to resolve any relative URLs inside the
error page.

In your case when you link to the stylesheet with just "styles.css" this
relative address is resolved differently, dependent on how you called
the error-causing page:

* www.example.com/archive
current directory is the site root /, so all relative URLs will be
resolved to start from there
-> www.example.com/styles.css

* www.example.com/archive/
current directory now is /archive/
-> www.example.com/archive/styles.css (which will cause a 404 error)

>Is it always recommended that a slash is
>always used to represent the relative url before a stylesheet name -


Yep, at least in this case.

>even if it's in the same folder as the pages that reference it?


It's an issue of how a browser resolves relative URLs.

>Is it
>better to always name the absolute url of the stylesheet? I'm wondering
>if there's a convention, or recommended policy.


I use root-relative URLs in most cases, whether they are really
necessary or not.

Micha
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      10-11-2004
mscir wrote:

> Can any body explain that? Is it always recommended that a slash is
> always used to represent the relative url before a stylesheet name -
> even if it's in the same folder as the pages that reference it?


A leading slash makes the URL an absolute reference instead of a relative
one. This means that wherever your page is within your site's structure,
the link to the stylesheet will always point to the right place.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
mscir
Guest
Posts: n/a
 
      10-12-2004
Toby Inkster wrote:

> mscir wrote:
>>Can any body explain that? Is it always recommended that a slash is
>>always used to represent the relative url before a stylesheet name -
>>even if it's in the same folder as the pages that reference it?

>
> A leading slash makes the URL an absolute reference instead of a relative
> one. This means that wherever your page is within your site's structure,
> the link to the stylesheet will always point to the right place.


Thanks to all who posted!
Mike
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Like all great travelers, I have seen more than I remember andremember more than I have seen. shenrilaa@gmail.com C Programming 0 03-05-2008 03:26 AM
Firefox and XSLT (local stylesheet works, server-based stylesheet fails) David Blickstein XML 14 10-15-2005 11:27 PM
xml:stylesheet use in document with multiple stylesheet options David Blickstein XML 3 08-02-2005 03:10 PM
have a stylesheet generate another stylesheet based on XML? Steven An XML 1 11-23-2004 01:07 PM
Stylesheet referanse i stylesheet =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?= XML 3 07-04-2004 03:16 PM



Advertisments