Apache 将db.example.com重写为example.com/db

Apache 将db.example.com重写为example.com/db,apache,Apache,我有一台apache服务器,我正在努力学习它的一些怪癖。。。 我已经让DNS将example.com指向1.2.3.4,并且在apache2服务器上设置了vhost 现在,我想在相同的vhost中,指向db.example.com以服务example.com/db的内容。 我希望我能用某种方式重写它,但到目前为止,我已经有了一堵墙 DNS部分已经涵盖,我只是不知道在apache中该做什么。在您的.htaccess文件中,尝试以下几行: RewriteEngine on RewriteCond %

我有一台apache服务器,我正在努力学习它的一些怪癖。。。 我已经让DNS将example.com指向1.2.3.4,并且在apache2服务器上设置了vhost

现在,我想在相同的vhost中,指向db.example.com以服务example.com/db的内容。 我希望我能用某种方式重写它,但到目前为止,我已经有了一堵墙


DNS部分已经涵盖,我只是不知道在apache中该做什么。

在您的
.htaccess
文件中,尝试以下几行:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^db\.example\.com 
RewriteRule (.*) http://example.com/db/$1 [L] 

非常感谢,这几乎解决了我的问题。有没有办法将http://db.example.com指向http://example.com/db,将https://db.example.com指向https://example.com/db?https和http都指向相同的sitecontent。请尝试添加RewriteCond%{https}=on作为http的条件之一,并尝试为SSL重写cond%{HTTPS}=on;我试过这样做:
RewriteCond%{HTTP_HOST}^db\.v42\.dk RewriteCond%{HTTPS}=关于重写规则(.*)的问题http://v42.dk/db/$1[L]#RewriteCond%{HTTP_HOST}^db\.v42\.dk RewriteCond%{HTTPS}=在RewriteRule(.*)上https://v42.dk/db/$1[L]
但无法使其工作。