在Apache '指令的正则表达式中,我如何才能避免使用符号' / ' ?

时间:2022-10-05 18:44:44

I wanted to serve .xhtml files as

我想把。xhtml文件作为

  • application/xhtml+xml if the browser says that it accepts it.
  • 如果浏览器说它接受application/xhtml+xml。
  • text/html otherwise
  • text / html否则

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`?).

我尝试过用mod_rewrite,但是它没有用选项follow symlinks(如果我有选项-FollowSymLinks,那么当我查看受Apache RewriteRule影响的文件时,为什么会被禁止403次?)

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.

…这是可行的,但我想要匹配正确的MIME类型。

2 个解决方案

#1


9  

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

您可以使用诸如\x2F之类的转义代码来代替/。

#2


5  

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

在Apache 2.4版本中,似乎还在进行改进。Apache团队成员“covener”推荐m#regexp#。

So your code would look like this...

所以你的代码是这样的…

<If "%{HTTP:Accept} !~ m#application/xhtml\+xml#">

#1


9  

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

您可以使用诸如\x2F之类的转义代码来代替/。

#2


5  

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

在Apache 2.4版本中,似乎还在进行改进。Apache团队成员“covener”推荐m#regexp#。

So your code would look like this...

所以你的代码是这样的…

<If "%{HTTP:Accept} !~ m#application/xhtml\+xml#">