logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: CGI and relative paths
Author
lee_is_me



Joined: 25 Jan 2009
Posts: 2

PostPosted: Sun 25 Jan '09 23:21    Post subject: CGI and relative paths Reply with quote

Hi all, first time posting.

I have Apache 2.0 installed on my Windows Vista box and I am trying out some things for CGI development.

The problem is that I'm not sure how to format links inside of my HTTP docs. For instance, I have the following link defined in a generated document:

Code:

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


The only way that the stylesheet is downloaded is if I place the forward slash in front of the file name for the style sheet.

If I put the style sheet in the same directory as the cgi, it doesn't work. I have to place the style sheet in the htdocs directory and append a foward class to the css file name like this:

Code:

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


This is fine for developing on my local machine but I am concerned that I will have problem when I upload the files to my hosted CPanel account.

Can someone shed some light on the relationship between the /cgi-bin directory and relative paths?

Thanks a bunch,

Lee
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 26 Jan '09 0:10    Post subject: Reply with quote

without the beginning slash, the stylesheet must be in the same folder as the html document.

with the slash in front, the stylesheet should be in the documentroot.

c:/apache2/cgi-bin <-- ScriptAlias
c:/apache2/cgi-bin/some.cgi
c:/apache2/htdocs <-- DocumentRoot
c:/apache2/htdocs/index.html
c:/apache2/htdocs/style.css
c:/apache2/htdocs/images/image.gif
c:/apache2/htdocs/faq/faqs.html

Index.html
------------------------------
<link rel="stylesheet" type="text/css" href="style.css" />
<img src="images/image.gif" />
<a href="faq/faqs.html">FAQs</a>
<a href="cgi-bin/some.cgi">Some CGI Script</a>


faqs.html
------------------------------
<link rel="stylesheet" type="text/css" href="/style.css" />
<img src="/images/image.gif" />
<a href="/index.html">Home</a>
<a href="/cgi-bin/some.cgi">Some CGI Script</a>

some.cgi
------------------------------
<link rel="stylesheet" type="text/css" href="/style.css" />
<img src="/images/image.gif" />
<a href="/index.html">Home</a>
<a href="/faq/faqs.html">FAQs</a>
Back to top
lee_is_me



Joined: 25 Jan 2009
Posts: 2

PostPosted: Mon 26 Jan '09 4:54    Post subject: Reply with quote

glsmith wrote:
without the beginning slash, the stylesheet must be in the same folder as the html document.

with the slash in front, the stylesheet should be in the documentroot.



Thank you. That was the problem that I ran into. I assumed that I could place the stylesheet in the same directory as the cgi app and not have to use the leading front slash, but that didn't seem to work.

Not a big deal if I have to place the CSS into the main or a sub directory of the main document root, just thought it was be easier to maintain if I could place the CSS in the same or actually, a sub directory of the cgi app.

Thanks again,

Lee
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 26 Jan '09 9:37    Post subject: Reply with quote

you can

c:/apache2/cgi-bin <-- ScriptAlias
c:/apache2/cgi-bin/some.cgi
c:/apache2/cgi-bin/css/style.css

some.cgi
--------------------------
<link rel="stylesheet" type="text/css" href="css/style.css" />

Index.html
------------------------------
<link rel="stylesheet" type="text/css" href="cgi-bin/css/style.css" />

faqs.html
------------------------------
<link rel="stylesheet" type="text/css" href="/cgi-bin/css/style.css" />

Below will NOT work faqs.html
<link rel="stylesheet" type="text/css" href="cgi-bin/css/style.css" />

-----------------------------------

no leadin slash = relative to the location of the calling document
leading slash = begin at docroot
Back to top


Reply to topic   Topic: CGI and relative paths View previous topic :: View next topic
Post new topic   Forum Index -> Apache