Forum Moderators: phranque

Message Too Old, No Replies

Accessing Files Outside Document Root

.htaccess fix?

         

rogerd

7:59 pm on May 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm reviewing a partially completed site where the designer is out of the picture. It looks like he intended to store lots of included files, including javascripts and site images, outside the document root (html) folder in a folder called stuff (at the same level as the html folder). So, you've got files that look like this:

/html/index.htm (site home page)
/stuff/pics/sample.jpg

Is this good practice for non-executable files, and is there an alias or rewrite command that will let the html pages request these? The developer was working in a subdirectory, so the image and other links are in the form of ../stuff/pics/sample.jpg. This worked fine while the site was in a subfolder on a larger site. Once the html folder becomes document root on its own domain, though, the links don't work.

The alternative is to move the files into the document root and change the references. Some of this can be automated, but some script editing may be needed and this will take some time.

Should we just recode the links, or is there an easy way to direct the requests to find the files?

encyclo

8:16 pm on May 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The easiest way would be with mod_alias [httpd.apache.org] (which is a pretty standard module on most Apache installs). You can define the aliases in httpd.conf or in the virtual host configuration, but not in a .htaccess so you will need root access.

You've got two different options: "Alias" and "ScriptAlias". For the images and such, you add the alias as follows:

Alias /pics /stuff/pics

ScriptAlias, as the name implies, is for CGI script directories such as a cgi-bin (ie. for executeable files, not just Javascript ones). It works in the same way. If your needs are more complex, there are the AliasMatch and ScriptAliasMatch directives where you can use regular expressions. All is better explained in the link above. :)

Your other possibility is simply to symlink the directories (assuming you're running a *nix OS), eg.:

ln -s /html/pics /stuff/pics

rogerd

10:32 pm on May 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



This will be in relatively cheap shared hosting, so I'm guessing editing httpd.conf is out. Where does that symlink code go? Thanks,