如何添加一个子域.htaccess指向根外部的文件夹 [英] how to add a sub domain .htaccess pointing to a folder outside the root
问题描述
我想要有一个子域指向正常的公共文件夹外的文件夹。
I want to have a sub domain that points to a folder outside the normal public root folder.
httpdocs/
sub_dom/
所以说admin.domain.com指向sub_dom而域 .com指向常规的httpdocs文件夹。
So say "admin.domain.com" points to "sub_dom" while "domain.com" points to the regular httpdocs folder.
- 这是可能的
- 是否有更好的解决方案(例如,以另一种方式更好/更可取)
目前,htaccess文件包含这个,但它不似乎做的诀窍:
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?
推荐答案
is this possible
它在vhost或服务器配置中。不可能使用htaccess文件,除非您可以通过常规域访问 / sub_dom /
目录。您不能使用您的htaccess文件访问您的文档根目录之外的任何目录。
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.
是否有更好的解决方案(例如,以另一种方式更好/更可取)
is there a better solution (for example would it be better/more advisable to do it another way)
正确的方法是创建一个新的虚拟主机您的旧vhost应该有这样的服务器名称:
The correct way to do it is to create a new vhost. Your old vhost should have server names something like this:
ServerName domain.com
ServerAlias www.domain.com
在您的新虚拟主机中,您有:
In your new vhost, you have:
ServerName admin.domain.com
And a: p>
And a:
DocumentRoot /path/to/sub_dom/
The Apache documentation has a tutorial for setting up vhosts.
或者,您可以从常规域创建别名,例如:
Alternatively, you can create an alias from your regular domain, something like:
Alias /sub_dom /path/to/sub_dom
然后你可以在您的domain.com文档根目录(httpdocs)中使用mod_rewrite:
Then you can use mod_rewrite in your domain.com document root (httpdocs):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^admin\.domain\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub_dom%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub_dom%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/sub_dom%{REQUEST_URI} -s
RewriteRule ^ /sub_dom%{REQUEST_URI} [L]
但是,您也可以将 / sub_dom /
code> httpdocs ,它会实现同样的事情。
But, you may as well just move /sub_dom/
into httpdocs
, it'll achieve the same thing.
这篇关于如何添加一个子域.htaccess指向根外部的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!