设置Apache的头有条件 [英] Set Apache headers conditionally

查看:185
本文介绍了设置Apache的头有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Apache服务器的工作,我想有条件地添加页眉。

如果该URI一定的正则表达式匹配,我想补充的标题访问控制允许来源:* 。什么是做到这一点的好办法?

我试过到目前为止:


  1. 我添加code。通过请求处理程序调用,使用 apr_table_add(rq-> headers_out,访问控制,允许原产地,*)。但似乎像Apache发送每当头 Content-Type的响应之前剥去头:应用程序/ x-的JavaScript 也被设置。这是错误的方式做到这一点?为什么阿帕奇剥去头?


  2. 我听说mod_headers中建议。是否mod_headers中必须把标题的能力的基础上与请求的正则表达式匹配的URI?



解决方案

  SetEnvIf之后REQUEST_URI somepartofurl SIGN
头总是加上访问控制允许来源,*ENV = SIGN

但只有位于配置这个工程。将其放入的.htaccess不会帮助。

I'm working with an apache server, and I'd like to add headers conditionally.

If the URI matches a certain regex, I'd like to add the header Access-Control-Allow-Origin: *. What is a good way to do this?

What I've tried so far:

  1. I added code called by the request handler, using apr_table_add(rq->headers_out, "Access-Control-Allow-Origin", "*"). But it seems like Apache strips the header before sending the response whenever the header Content-Type: application/x-javascript is also set. Is this the wrong way to do it? Why would Apache strip the header?

  2. I've heard mod_headers suggested. Does mod_headers have the capability to place headers based on regex matching with the request URI?

解决方案

SetEnvIf Request_URI somepartofurl SIGN
Header always add "Access-Control-Allow-Origin" "*" env=SIGN

but this works only if located in the configuration. Placing it into .htaccess won't help.

这篇关于设置Apache的头有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆