Forum Moderators: coopster

Message Too Old, No Replies

Linking to files outside the doc root

What are the options?

         

cybersphere

4:22 am on May 18, 2006 (gmt 0)

10+ Year Member



If I create a simple html file that contains a hyperlink to a text file outside of my doc. root, and open this in the browser using the File, Open File command, the hyperlink works as expected.

However, if I open the same html file by using a localhost path, so that the html is served by Apache, clicking on the hyperlink has no effect.

It appears that Apache can resolve the file link, but it chooses not to, presumably for security reasons.

Is there any way to override this, and allow hyperlinks to files outside the doc. root?

I am aware of the alias command, but this is not quite what I want. I want to be able to issue a general directive saying that referencing any file on the system is OK. The application will only run locally, so I don't have security concerns.

mcavic

5:41 am on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apache can't access files outside the document root, because there's no way to address them. For example, /file refers to "file" under the document root, not "file" in the system root.

But, if you're using Linux, try making a symbolic link pointing from inside the document root to outside. There is a directive allowing Apache to follow symlinks.

I have this in my httpd.conf:

<Directory />
Options FollowSymLinks ExecCGI Includes
AllowOverride All
</Directory>

cybersphere

6:09 am on May 18, 2006 (gmt 0)

10+ Year Member



Thanks.

I eventually decided to simply create a hyperlink back to the current script with a querystring containing the file I wanted to display. If the script detected that the relevant $_GET parameter was set, it would simply display the file using PHPs file functions.

This works OK.