Apache RewriteCond 防止死循环

Apache RewriteCond to prevent infinite loop

我正在为我的网站使用 Google Analytics,它在页面上运行良好,问题是 mp3 文件,当它们被直接访问时我想直接访问它们。

我有一个 php 文件如下:

<?php 

error_log("hiiiiiiiii--".$_SERVER['REQUEST_URI']); // for testing
error_log("meeeeeeeee--".$_SERVER["HTTP_REFERER"]); // for testing
//header("location:".$_SERVER['REQUEST_URI']);

?>

<html>
    <body>
        <script>
            //GA code goes here
            window.location = ("<?php echo $_SERVER['REQUEST_URI']; ?>");
        </script>
    </body>
</html>

在音频文件的根文件夹中的 .htaccess 中:

#RewriteCond %{SCRIPT_NAME} !(counter) #Here is the problem
RewriteRule ^(.*)\.mp3$ /media/counter\.php [L]

请求重定向到 counter.php 并重定向到 .mp3 文件,但这显然会造成无限循环。 我需要的是 RewriteCond,如果 http_refferer 或 script_name 包含名称 "counter",则不会重定向到 counter.php。

感谢您的帮助

What I need is the RewriteCond such that if http_refferer or script_name contains the name "counter" DOES NOT redirect to counter.php.

试试这条规则:

RewriteCond %{HTTP_REFERER} !counter [NC]
RewriteCond %{REQUEST_URI} !counter [NC]
RewriteRule ^.+?\.mp3$ media/counter\.php [L,NC]