【问题标题】:Do I need PHP to serve an HTTP Header with the correct content-type for RSS/ATOM?我是否需要 PHP 为 RSS/ATOM 提供具有正确内容类型的 HTTP 标头?
【发布时间】:2010-12-06 03:29:03
【问题描述】:

我想发送带有正确 Content-type 标头的 RSS/Atom 提要,我可以在不访问 PHP 或任何其他服务器端语言的情况下执行此操作吗?目标是让浏览器将文件视为提要,而不仅仅是纯 XML 文件。

【问题讨论】:

    标签: php xml http rss atom-feed


    【解决方案1】:

    您可以告诉服务器发送具有特定媒体类型的特定文件。

    Apache 有 AddTypeForceType 指令来做到这一点:

    # send all .atom files with application/atom+xml
    AddType application/atom+xml .atom
    
    # send only foo.bar as application/atom+xml
    <FilesMatch ^foo\.bar$>
        ForceType application/atom+xml
    </FilesMatch>
    

    您可以使用 &lt;Directory&gt;&lt;DirectoryMatch&gt;&lt;Files&gt;&lt;FilesMatch&gt;&lt;Location&gt;&lt;LocationMatch&gt; 部分将指令限制为仅针对特定目录、文件或 URL 路径。但请注意context 允许它们进入。只有&lt;Files&gt;&lt;FilesMatch&gt; 可以在.htaccess 文件中使用。

    【讨论】:

      【解决方案2】:

      如果您的 RSS/ATOM 提要具有特定的扩展名,或者是从特定目录提供的,我想您可以使用 Apache 的 AddType directive,因此 Apache 将为您的 RSS 提要提供正确的内容类型:

      AddType 指令映射给定的 文件扩展名到指定的 内容类型。 MIME 类型是 MIME 用于包含的文件名的类型 扩展名。


      未经测试,但我想像这样的东西,无论是在你的 Apache 的主配置文件中,还是在 .htaccess 文件中,对于 RSS 提要都可能这样做:

      AddType application/rss+xml .rss
      

      而且,对于 ATOM,可能是这样的:

      AddType application/atom+xml .atom
      

      【讨论】:

        猜你喜欢
        • 2011-08-05
        • 2010-09-25
        • 1970-01-01
        • 2013-04-01
        • 1970-01-01
        • 2013-12-11
        • 1970-01-01
        • 2010-10-10
        • 2013-01-23
        相关资源
        最近更新 更多