Carlos
Carlos

Reputation: 160

Apache - give access to "shared" directory on server

Running into a bit of an issue here whereas I would like to configure my apache server to let one subdomain access another's files (shared) to eliminate the need and overhead of direct URL calls.

For example, I would like my primary domain (site.domain.com) to access the images located in a "share" domain (share.domain.com/images).

The directory structure is as follows:

- subdomains
    - site
    - share

I have an site.domain.com/index.html file containing the following...

<img src="http://share.domain.com/images/img.jpg"> (works)
<img src="../share/images/img.jpg"> (does not work)

And no matter how many "../" I add I still cannot get out of the directory. Which is shown when I do a "view image" on the one that did not work.

How could I fix this?

Upvotes: 2

Views: 16880

Answers (2)

NauT
NauT

Reputation: 426

Lets imagine that your site is under /var/www/site (site.domain.com) and your share folder is under /var/www/share (share.domain.com).

If you would like to have share as just a subdirectory accessible from site.domain.com/share all you will need to do its to create a symlink from /var/www/share to /var/www/site/share:

ln -s /var/www/share /var/www/site/share

Upvotes: 1

Ovar Feisyl
Ovar Feisyl

Reputation: 103

DISCLAIMER: I am not an expert.

I think the reason you cannot access the shared area is that is is not under your DocumentRoot, after looking at the documentation I think that what you want is the Alias directive; the documentation for which can be found at:

http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias

An example of the usage is:

Alias /share path-to-share
<Directory path-to-share>
    Order allow,deny
    Allow from all
</Directory>

You would need to put that into the <VirtualHost> block in your configuration. Doing this maps /share/imgages/img.jpg to <path-to-share>/images/img.jpg so that you can access it like the files are in your DocumentRoot.

With this setup your example would become:

<img src="http://share.domain.com/images/img.jpg"> (works)
<img src="/share/images/img.jpg"> (should work)

I hope this helped.

Upvotes: 1

Related Questions