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.开发者_JS百科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.
If you're not doing any url modification/fancy matching, why not try
<VirtualHost ...>
// sub1 site
Redirect /sub2 http://sub2.example.com
</VirtualHost>
mod_rewrite is heavy artillery when all you really need is a pea shooter.
That, or use an alias:
Alias /sub2 /full/path/to/equivalent/directory/in/sub2
精彩评论