TL;DR: Is there any way to have a domain's sub-directory
http://company.com/subdir
point to a directory outside the web root using only.htaccess
with no access to the server's configuration?
I have a web site company.com
that runs three country-specific copies of a CMS on a shared hosting package (Apache 2, PHP 5).
The CMS is split into two directories:
/app <----- Non-public content, to be placed outside the web root
/htdocs <----- Public content
I would like to have each of the three country-specific CMSes as sub-directories to the main domain:
www.company.com/de/ <-- 1st copy
www.company.com/ch/ <-- 2nd copy
www.company.com/at/ <-- 3rd copy
the obvious problem with this structure, each CMS's /app
directory would need to be put into a separate location outside the web root. However, for maintenance reasons (I am passing on my projects to another company) I would like to prevent this.
The ideal solution for me would be that each copy of the CMS resides in a directory outside the web root:
/htdocs <------- public web root
/de/app
/de/htdocs
/ch/app
/ch/htdocs
/at/app
/at/htdocs
thus ensuring that the app
directory can't be accessed from outside.
Each CMS's public htdocs
directory would be made available to the world selectively using an Alias
directive:
Alias /de ../de/htdocs
Alias /ch ../ch/htdocs
Alias /at ../at/htdocs
But this is not possible from within .htaccess
(I get a 500 error) where Alias
directives are not possible to specify, and as far as I know, mod_rewrite
directives can only specify targets inside the web root (correct?)
As far as I can see, what I want to do is impossible to do in a shared hosting environment, but I thought I'd check whether anybody here has any ideas, as it would be a huge relief for me to be able to do it this way.
I can put a .htaccess into the parent directory (one level above web root), but that doesn't seem to change anything.
I hope it's put clear enough. If it isn't, please let me know and I will clarify.
Switching away from the shared hosting is not an option, neither is asking the hosting company about relaxing the rules - they are very good at what they do, but also very strict and conservative about individual customizations.
Leaving each app
directory in the web root, and blocking access to it using Deny from all
or similar, is not an option either.
The "Alias" directive is not allowed in .htaccess files. According to http://httpd.apache.org/docs/current/mod/mod_alias.html#alias, "Alias" is only allowed in "server config, virtual host". That's why you get a 500 error when you set it in the .htaccess context.
It's helpful to review the context flag in the apache manual when you have a server error, if you're unsure of the context proper for your directive.
I think you might easily accomplish this with some symlinks, if your host allows FollowSymlinks: