I wanted to serve .xhtml files as
application/xhtml+xml
if the browser says that it accepts it.text/html
otherwiseI 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.
You escape it by putting a backward slash in front of it: \/ For some languages (like PHP) you can use other characters as the delimiter and therefore you don't need to escape it.
A slash symbol '/' is not a special character, but in JavaScript it is used to open and close the regexp: /... pattern.../ , so we should escape it too.
There are two ways to create a regular expression instance. One way uses forward slash characters ( / ) to delineate the regular expression; the other uses the new constructor. For example, the following regular expressions are equivalent: var pattern1:RegExp = /bob/i; var pattern2:RegExp = new RegExp("bob", "i");
You could use an escape code like \x2F
instead of the /
.
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#">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With