I want to have a sub domain that points to a folder outside the normal public root folder.
httpdocs/
sub_dom/
So say “admin.domain.com” points to “sub_dom” while “domain.com” points to the regular httpdocs folder.
- is this possible
- is there a better solution (for example would it be better/more advisable to do it another way)
Currently the htaccess file contains this but it does not seem to do the trick:
RewriteCond %{HTTP_HOST} ^admin\.domain\.com$
RewriteRule ^/(.*) /var/www/vhosts/domain.com/sub_dom/admin/ [redirect,last]
There is most probably something very wrong with the second line maybe?
It is in vhost or server config. It is not possible using an htaccess file unless you can already access the
/sub_dom/directory via your regular domain. You can’t access any directory outside of your document root using your htaccess file.The correct way to do it is to create a new vhost. Your old vhost should have server names something like this:
In your new vhost, you have:
And a:
The Apache documentation has a tutorial for setting up vhosts.
Alternatively, you can create an alias from your regular domain, something like:
Then you can use mod_rewrite in your domain.com document root (httpdocs):
But, you may as well just move
/sub_dom/intohttpdocs, it’ll achieve the same thing.