有没有办法将 apache2 中的路径重定向到另一个虚拟主机
我在一台计算机上运行多个虚拟主机,并且我想覆盖从一台虚拟主机到另一台虚拟主机的一条路径。我最初的计划是使用 mod rewrite,但我被绝对 URL 困住了。
我想要以下行为(不使用 301 重定向):
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
我正在使用以下配置对此进行测试:
<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 时,apache2 返回“400 Bad Request”并放置这在日志文件中。
[Fri Jul 08 16:09:05 2011] [error] [client 127.0.0.1] Invalid URI in request GET /sub2/ HTTP/1.1
我还尝试在 sub2 域内使用 ServerPath ,但是那也行不通。
I have several virtual hosts running on one machine, and I would like to override one path from one virtual host onto another. My original plan was to use mod rewrite, but I got stuck on the absolute URL.
I would like the following behavior, (without using 301 redirects.):
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
I was testing this out with the following configuration:
<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>
I am running a Python WSGI application in each subdomain. When you access http://sub1.example.com/sub2 apache2 returns "400 Bad Request" and puts this in the log file.
[Fri Jul 08 16:09:05 2011] [error] [client 127.0.0.1] Invalid URI in request GET /sub2/ HTTP/1.1
I have also tried using ServerPath inside of the sub2 domain, but that also doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你不做任何 url 修改/花哨的匹配,为什么不尝试
mod_rewrite 是重炮,而你真正需要的是豌豆射手。
那,或者使用别名:
If you're not doing any url modification/fancy matching, why not try
mod_rewrite is heavy artillery when all you really need is a pea shooter.
That, or use an alias: