Forum Moderators: phranque

Message Too Old, No Replies

Path issues and SSI

         

rogerd

2:51 am on Mar 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've got a question for which the answer is either simple or impossible...

I've got a forum which generates its pages using a template and cgi script. I've set the script to insert a server side include in each page for ad rotation. So, for example, the script might stuff this into each page:

<!--#include virtual="/cgi-bin/program.cgi" -->

The problem is that this code gets stuffed into files at various directory levels, e.g.,

mysite.com/file.htm
mysite.com/dir/file2.htm
mysite.com/dir/sub/file3.htm

The relative path to the script changes for each file. So, if the code works at one level it's broken on the others. Is there a way to do an include of this type with an absolute reference? Is a BASE tag a workable approach?

EBear

11:01 am on Mar 25, 2004 (gmt 0)

10+ Year Member



Apparantly you can't access a CGI script with virtual.

[hoohoo.ncsa.uiuc.edu...]

rogerd

1:55 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually, the script executes fine if the virtual path is correct.

The problem is that the path changes depending on where the web page is located in the directory structure.

EBear

3:31 pm on Mar 25, 2004 (gmt 0)

10+ Year Member



Are you starting the path at the server root? With a virtual address the path should not change, and the leading "/" indicates the root of the server. (i.e. write the path as you would in index.html and start it with a "/".)

rogerd

3:48 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I tried using the full path, something like,
/domain/www/cgi-bin/program.cgi
but that didn't seem to work at all. Should that work? I might have messed it up somehow. What DOES seem to work is adjusting the relative path depending on the level of the page, e.g.,
../cgi-bin/program.cgi
Unfortunately, the pages are generated by the software and for a variety of reasons I don't want to rewrite that.

jdMorgan

4:20 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is very odd. The mod_include documentation clearly states that if an included URL does not begin with a slash, then it is taken as relative to the current (including) document. This implies that if the URL-path does begin with a slash, then it should be taken as relative to the Web root directory. Indeed, this is how it behaves on my server.

I suspect something is mis-configured, but I don't know where or how. A work-around might be to use mod_rewrite and a very unique script filename, and rewrite all requests for that script to a fixed directory path.

<added>
Another option is to leave out "virtual" and use a full URL:
<!--#include="http://www.yourdomain.com/cgi-bin/program.cgi" -->
</added>

Jim

rogerd

2:20 am on Mar 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Jd, I tried the full URL approach and got the dreaded "[an error occurred while processing this directive]"... :(

isitreal

4:05 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I had a problem like this with SSI, on my development server, the paths wouldn't work at all, after looking a while I found this solution:

<Directory "c:/yoursite/mainfolder">
Options +Includes
</Directory>

I had forgotten the + in front of Includes, after I put it back in, everything worked fine, that's using the absolute path to the root of your site, not your server, like /cgi-bin/filename.cgi

rogerd

4:25 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Thanks, Isitreal. Where did you put this code?

isitreal

5:00 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have access to your main apache httpd.conf file, put it in your site's virtual directory area, that's at the bottom of the httpd.conf file, if you don't put it in the main, root level .htaccess file for the site, I haven't tried it in an .htaccess file, but I think it works just like that, of course you have to change the paths to your site folder paths.

Actually, I think you could just add the line:

Options +Includes

to the .htaccess file, try it and see.