Pregunta

I wanted to serve .xhtml files as

  • application/xhtml+xml if the browser says that it accepts it.
  • text/html otherwise

I tried doing it with mod_rewrite but it didn't work with Options -FollowSymLinks (see Why I do I get 403 Forbidden when viewing files affected by Apache RewriteRule if I have `Options -FollowSymLinks`?).

Then, I tried

<Files "*.xhtml">
    <If "%{HTTP:Accept} !~ /application\/xhtml\+xml/">
        ForceType text/html
    </If>
</Files>

But I get a syntax error: Failed to compile regular expression.

Meanwhile, I use this code...

<Files "*.xhtml">
    <If "%{HTTP:Accept} !~ /xhtml\+xml/">
        ForceType text/html
    </If>
</Files>

... which works, but I want to match the correct MIME type.

¿Fue útil?

Solución

You could use an escape code like \x2F instead of the /.

Otros consejos

It looks like improving this is still under construction as of Apache 2.4. Apache team member "covener" recommends m#regexp# instead.

So your code would look like this...

<If "%{HTTP:Accept} !~ m#application/xhtml\+xml#">
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top