views:

437

answers:

2

I'm starting up a new web-site, and I'm having difficulties enforcing my desired file/folder organization:

For argument's sake, let's say that my website will be hosted at: http://mywebsite.com/

I'd like (have set up) Apache's Virtual Host to map http://mywebsite.com/ to the /fileserver/mywebsite_com/www folder.

The problem arises when I've decided that I'd like to put a few files (favicon.ico and robots.txt) into a folder that is ABOVE the /www that Apache is mounting the http://mywebsite.com/ into

robots.txt+favicon.ico go into => /fileserver/files/mywebsite_com/stuff

So, when people go to http://mywebsite.com/robots.txt, Apache would be serving them the file from /fileserver/mywebsite_com/stuff/robots.txt

I've tried to setup a redirection via mod_rewrite, but alas:

RewriteRule ^(robots\.txt|favicon\.ico)$ ../stuff/$1 [L]

did me no good, because basically I was telling apache to serve something that is above it's mounted root.

Is it somehow possible to achieve the desired functionality by setting up Apache's (2.2.9) Virtual Hosts differently, or defining a RewriteMap of some kind that would rewrite the URLs in question not into other URLs, but into system file paths instead? If not, what would be the preffered course of action for the desired organization (if any)?

I know that I can access the before mentioned files via PHP and then stream them - say with readfile(..), but I'd like to have Apache do as much work as necessary - it's bound to be faster than doing I/O through PHP.

Thanks a lot, this has deprived me of hours of constructive work already. Not to mention poor Apache getting restarted every few minutes. Think of the poor Apache :)

+1  A: 

Can you use symlinks?

ln -s /fileserver/files/mywebsite_com/stuff/robots.txt /fileserver/files/mywebsite_com/stuff/favicon.ico /fileserver/mywebsite_com/www/

(ln is like cp, but creates symlinks instead of copies with -s.)

strager
Of course, syms could work, but that's not the issue here. I've whipped out those two files just for example. What I would really love is a concrete redirection using apache's resources. Thanx for the tip though.
Limo Driver
Is the issue clutter? What real benefit do you get to putting the files in anything other than the root website directory?
Randolpho
Not so much as clutter, for I could have placed the files in /fileserver/mywebsite/www/stuff instead. I'd just really love the described functionality. The files being outside the www folder, noone could get access to them even if .htaccess was removed-not likely though. I just plain like the idea.
Limo Driver
@Limo Driver, If you don't want people to have access to them, change the permissions. If your apache user ('www-data' in many installations) is the owner of the file, set the file to mode 600 (-rw-------) with: chmod 600 file names here.
strager
What does that mean "no one could get access to them?" Don't you want access? The two examples you give are files that you want to be accessed. They belong in your web root.
bmb
+2  A: 

It seems you are set to using a RewriteRule. However, I suggest you use an Alias:

Alias /robots.txt /fileserver/files/mywebsite_com/stuff/robots.txt

Additionally, you will have to tell Apache about the restrictions on that file. If you have more than one file treated this way, do it for the complete directory:

<Directory /fileserver/files/mywebsite_com/stuff>
    Order allow,deny
    Allow from all
</Directory>
innaM
+1 using mod_rewrite for that is way overkill.
Keltia
This is EXACTLY what I was looking for!I've used Alias before but only for redirecting to other directories. Didn't occur to me that I could use it for specific web-site resources . Thanx a lot!
Limo Driver