我有一个分析文件(php 格式),我想将其添加到我网站上的每个页面上,以便我可以监视访问了哪些页面。我将如何设置 .htaccess 文件来实现此目的?
目前我有:
<Files "*">
php_value auto_prepend_file /analytics.inc.php
</Files>
但它没有按预期工作。
另外,如果有人可以建议一种更简单的方法来收集网站分析,我会洗耳恭听。
编辑:
我希望将分析文件添加到所有(子)目录中的所有文件之前。目前只有根目录的文件被添加到前面。
I have an analytics file (in php) that I would like to prepend to every page on my site so that I can monitor which pages are visited. How would I set up my .htaccess file to achieve this?
Currently I have:
<Files "*">
php_value auto_prepend_file /analytics.inc.php
</Files>
but it's not working as desired.
Also, if anyone can suggest a simpler way to collect site analytics, I'm all ears.
EDIT:
I would like the analytics file to be prepended to all files in all (sub)directories. Currently only the root directory is having its files prepended.
发布评论
评论(3)
路径肯定不正确。它应该是文件系统脚的绝对路径。
您的网络服务器已经记录了每个请求。
您唯一需要的就是每天解析这些日志并收集您需要的任何统计数据。
请注意,网络服务器会记录每个请求,因此它有其优点和缺点。
它不仅会记录对 PHP 文件的请求,就像您的情况一样,还会记录对静态文件的请求,例如图像、pdf 等。
但它也会记录页面上的每个图像,因此,对常用页面的一次请求将在日志文件中产生多达数百条记录。因此,您必须选择要分析的记录。
The path is incorrect for sure. it should be absolute path from the filesystem foot.
Your web-server already logs every request.
Only thing you need is to parse these logs daily and collect any stats you need.
Note that web-server logs every request, so, it has it's advantages and disadvantages.
It will log not only requests to PHP files as it in your case but to static files too, like images, pdfs and such.
But it will also log every image on the page, so, one request to usual page will produce up to hundred records in the log file. So, you have to choose records to analyze.
尝试删除
和并执行以下操作:
同时确保analytics.inc.php 的路径正确,它与 .htaccess 位于同一目录中。
如果仍然不起作用,查看 apache 错误日志文件可能会有所帮助。
Try removing the
<Files "*">
and</Files>
and just do:Also make sure that the path to analytics.inc.php is correct, and its in the same dir as the .htaccess.
If it still doesn't work, seeing your apache error log file could help.
尝试在.htaccess 中提供analytics.inc.php 文件的绝对路径。 IIRC,前置指令查找与您要包含的文件相关的文件。
Try giving an absolute path to the analytics.inc.php file in the .htaccess. IIRC, the prepend directive looks for the file relative to the file you are including it into.