更改一个用户代理的 MIME 类型

更改一个用户代理的 MIME 类型

我正在尝试仅为特定用户代理(Chrome)覆盖文件的 mime 类型,并保留其他用户代理(Firefox)的默认类型。

Options +Indexes
IndexOptions -FancyIndexing
Header set Access-Control-Allow-Origin "*"


RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.org$
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]


# Turn off MultiViews
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType "application/rdf+xml" .rdf
AddType "text/turtle" .ttl

# Rewrite engine setup
RewriteBase /

# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^$ index.rdf [R=303]

# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^$ index.ttl [R=303]

# firefox display xml by default but downloads turtle
RewriteCond %{HTTP_USER_AGENT} Firefox/.*
RewriteRule ^$ index.rdf [R=303]

# make chrome display xml file with faking MIME type to application/xml instead application/rdf+xml
RewriteCond %{HTTP_USER_AGENT} ^.*Chrome/.*$
RewriteCond %{REQUEST_URI} ^/index.rdf$
RewriteRule ^index.rdf - [T=application/xml]

# Choose the default response (turtle for chrome safari ...which display turtle as raw text)
# Serve RDF/XML by default
RewriteRule ^$ index.ttl [R=303]

原因是 mimetypeapplication/xml在 chrome 中内联显示,但application/rdf+xml会被下载。我想保留它,application/rdf+xml只为 chrome 更改它。但在我的配置下,firefox 也会得到错误的 mimetype。

相关内容