You could use an escape code like \x2F
instead of the /
.
How can I escape slash sign `/` in Apache `<If>` directive's regex?
-
16-03-2022 - |
Вопрос
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.
Решение
Другие советы
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#">
Не связан с StackOverflow