【问题标题】:Apache httpd: Change Content-Type of global redirect to application/jsonApache httpd:将全局重定向的 Content-Type 更改为 application/json
【发布时间】:2018-07-17 21:23:19
【问题描述】:

我的机器上运行了一个 Apache 2.2 http 服务器,用于测试目的。它在特定端口上所做的只是重定向到外部站点。

我的 httpd.conf 文件中的 VirtualHost 部分如下所示:

<VirtualHost *:8001>
    ServerName localhost
    Redirect / http://www.google.com
    LogLevel debug
</VirtualHost>

现在当我这样做时,得到的 http 响应有

Content-Type: text/html; charset=iso-8859-1

但我希望 Content-Type 为 application/json。有什么方法可以实现吗?

我发现this 问题的答案是使用Header set Content-type ...,但这对我没有任何改变。

【问题讨论】:

    标签: apache httpresponse virtualhost httpd.conf http-redirect


    【解决方案1】:

    你必须使用“always”修饰符来确保它在所有情况下都会发生,在这种情况下你需要它。

    <VirtualHost *:8001>
        ServerName localhost
        Redirect / http://www.google.com/
        Header always set Content-Type "application/json"
    </VirtualHost>
    

    你会得到类似的东西:

    HTTP/1.1 302 Found
    Date: Wed, 07 Feb 2018 18:30:42 GMT
    Server: Apache
    Content-type: application/json
    Location: http://www.google.com/
    

    【讨论】:

    • 你好,但是如果我只想将它应用到一个特殊的目录,我应该怎么做?例如:我想在特殊路径 *.com/foo 中将所有 .js 文件更改为“application/json”,谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多