2011-07-08 17 views
0

我在一台机器上运行了多个虚拟主机,并且我想重写从一个虚拟主机到另一个虚拟主机的一条路径。我原来的计划是使用国防部重写,但我坚持绝对的网址。有没有办法将apache2中的路径重定向到另一个虚拟主机

我想以下行为,(不使用301个重定向。):

<VirtualHost *:80> 
    <Directory /var/lib/wsgi> 
    Order allow,deny 
    Allow from all 
    </Directory> 

    ServerName sub1.example.com 
    WSGIScriptAlias//var/lib/wsgi/sub1.wsgi 
    WSGIDaemonProcess sub1 display-name=%{GROUP} 
    WSGIProcessGroup sub1 

    RewriteEngine on 
    RewriteRule ^/sub2/(.*)$ http://sub2.example.com/sub2/$1 [PT] 

</VirtualHost> 

<VirtualHost *:80> 
    <Directory /var/lib/wsgi> 
    Order allow,deny 
    Allow from all 
    </Directory> 

    ServerName sub2.example.com 
    WSGIScriptAlias//var/lib/wsgi/sub2.wsgi 
    WSGIDaemonProcess sub2 display-name=%{GROUP} 
    WSGIProcessGroup sub2 
</VirtualHost> 

我运行一个Python WSGI应用:

http://sub1.example.com/sub2 -> sub2.example.com virtual host 
# Everything but sub2/.* 
http://sub1.example.com/  -> sub1.example.com virtual host 
http://sub2.example.com/  -> sub2.example.com virtual host 

我是用下面的配置测试了这一点在每个子域中。当您访问http://sub1.example.com/sub2时,apache2返回“400错误请求”并将其放入日志文件中。

[Fri Jul 08 16:09:05 2011] [error] [client 127.0.0.1] Invalid URI in request GET /sub2/ HTTP/1.1 

我也曾尝试使用ServerPath的SUB2域之内,但也不能正常工作。

回答

1

如果你没有做任何修改URL /花哨的匹配,为什么不尝试

<VirtualHost ...> 
    // sub1 site 
    Redirect /sub2 http://sub2.example.com 
</VirtualHost> 

mod_rewrite的是,当你真正需要的是豌豆射手重炮。

也就是说,或使用一个别名:

Alias /sub2 /full/path/to/equivalent/directory/in/sub2 
+0

重定向将客户端发送到另一个站点。我想从sub1中访问站点的客户端隐藏sub2虚拟主机。别名仅适用于磁盘上的路径,并且不允许您修改主机名。 – user835673

+0

然后使用别名,它会使sub2网站中/ sub2下的sub2网站的内容可用。 –

+1

从我读过的内容中,您不能使用别名将流量定向到其他虚拟主机。如果sub2正在提供静态文件,但是它正在运行WSGI脚本,则这会起作用。 – user835673

相关问题