1

I'm trying to overwrite the mime type of a file for a specific User Agent only (Chrome) and leave the default for the others (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]

The reason for this is that the mimetype application/xml gets displayed inline in chrome but application/rdf+xml gets downloaded. I'd like to leave the it be at application/rdf+xml and only change it for chrome. But with my config firefox also gets the wrong mimetype.

koma5
  • 11
  • 2
  • "`[T=aplication/xml]`" - shouldn't this be `[T=application/rdf]`? Have you confirmed the `User-Agent` and `Content-Type` is the request/response headers? You should also be including `L` flags on your `RewriteRule` directives, otherwise, processing will continue through the file. – MrWhite Jul 28 '17 at 16:14
  • no that's correct: https://www.w3.org/TR/rdf-syntax-grammar/#h2_section-MIME-Type . Yes... In the user-agent contains either Chrome or Firefox but not both. But Firefox get's caught in the rewrite rule from chrome. Very strange. The content-type gets changed. That's how I know firefox gets the wrong one. L flags didn't solve my problem. – koma5 Aug 02 '17 at 08:50
  • "no that's correct" - it was just that in your last paragraph, you make reference to `application/rdf` - is that in error? But `[T=aplication/xml]` is missing a `p` - so that's not correct either. (?) – MrWhite Aug 03 '17 at 23:02
  • ohh silly me... you are right, my last paragraph is wrong and there's a typo in my config! But still my config hasn't the disired effect: Rewrite Chrome only... – koma5 Aug 04 '17 at 06:08

0 Answers0