我的网站使用 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]
关于php - Apache RewriteCond 防止无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30154106/