Oriol Oriol - 1 year ago 93
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download