Oriol Oriol - 6 months ago 32
Apache Configuration Question

How can I escape slash sign `/` in Apache `<If>` directive's regex?

I wanted to serve .xhtml files as

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

  • text/html

I tried doing it with
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

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

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


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