标题集访问控制允许来源不与mod_rewrite + mod_jk工作

我在SF上的第一个问题,所以请原谅我,如果我设法博克的职位。 🙂

无论如何,我在我的一台机器上使用了mod_rewrite,并且有一条简单的规则,可以在另一台机器上redirect到一个webapp。 我也在这两台机器上设置标题“Access-Control-Allow-Origin”。 问题是当我重写规则时,我放弃了“Access-Control-Allow-Origin”标题设置。

以下是第一台机器的Apacheconfiguration示例:

NameVirtualHost 10.0.0.2:80 <VirtualHost 10.0.0.2:80> DocumentRoot /var/www/host.example.com ServerName host.example.com JkMount /webapp/* jkworker Header set Access-Control-Allow-Origin "*" RewriteEngine on RewriteRule ^/otherhost http://otherhost.example.com/webapp [R,L] </VirtualHost> 

下面是第二个Apacheconfiguration的例子:

 NameVirtualHost 10.0.1.2:80 <VirtualHost 10.0.1.2:80> DocumentRoot /var/www/otherhost.example.com ServerName otherhost.example.com JkMount /webapp/* jkworker Header set Access-Control-Allow-Origin "*" </VirtualHost> 

当我点击host.example.com我们看到标题已设置:

 $ curl -i http://host.example.com/ HTTP/1.1 302 Moved Temporarily Server: Apache/2.2.11 (FreeBSD) mod_ssl/2.2.11 OpenSSL/0.9.7e-p1 DAV/2 mod_jk/1.2.26 Content-Length: 0 Access-Control-Allow-Origin: * Content-Type: text/html;charset=ISO-8859-1 

当我打到otherhost.example.com我们看到它也是设置标题:

 $ curl -i http://otherhost.example.com HTTP/1.1 200 OK Server: Apache/2.0.46 (Red Hat) Location: http://otherhost.example.com/index.htm Content-Length: 0 Access-Control-Allow-Origin: * Content-Type: text/html;charset=UTF-8 

但是当我尝试在host.example.com/otherhost重写重写规则时,我们得不到任何爱:

 $ curl -i http://host.example.com/otherhost/ HTTP/1.1 302 Found Server: Apache/2.2.11 (FreeBSD) mod_ssl/2.2.11 OpenSSL/0.9.7e-p1 DAV/2 mod_jk/1.2.26 Location: http://otherhost.example.com/ Content-Length: 0 Content-Type: text/html; charset=iso-8859-1 

有人可以指出我在这里做错了吗? mod_jk可以成为问题的一部分吗?

我已经成功地使用了:

 SetEnvIf Origin "http(s)?://(domaine1\.com|domain2\.com)$" AccessControlAllowOrigin=$0 Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin 

来自http://www.cameronstokes.com/2010/12/26/cross-origin-resource-sharing-and-apache-httpd/

由于这是一个redirect,因为一些不幸的Apache内部原因,你需要“he​​ader set always …”。 只要你没有编辑/覆盖现有的头文件,“总是”是合理的,只是在没有多less担心的情况下拍。