有没有办法将 apache2 中的路径重定向到另一个虚拟主机

发布于 2024-11-19 09:27:31 字数 1515 浏览 2 评论 0原文

我在一台计算机上运行多个虚拟主机,并且我想覆盖从一台虚拟主机到另一台虚拟主机的一条路径。我最初的计划是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宁愿没拥抱 2024-11-26 09:27:32

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

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

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

那,或者使用别名:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文