如何从 htaccess 中排除本地主机?

How to exclude localhost from htaccess?

我在我的 .htaccess 中使用以下指令来执行我们的脚本 PHP 7 :

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php-7
</FilesMatch>

它在我的生产服务器上运行良好,但在本地主机上运行不正常。所以我的问题是:如何从 FilesMatch 指令中排除本地主机?

我尝试了很多东西。 "Directory" 和 "DirectoryMatch" 不能在 .htaccess 中使用。 "If" 可以在 .htaccess 中使用,但由于某些原因,以下内容不起作用:

<If "%{HTTP_HOST} != 'localhost'">
    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
        SetHandler application/x-httpd-php-7
    </FilesMatch>
</If>

我终于发现它在反转 "FilesMatch" 和 "If" 标签时有效:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    <If "%{HTTP_HOST} != 'localhost'">
        SetHandler application/x-httpd-php-7
    </If>
</FilesMatch>

我不知道为什么,但它有效。