在.htaccess中加载的每个页面上运行PHP脚本


Run PHP script on every page load in .htaccess

我创建了一个用PHP计算的命中率,该命中率保存到数据库中,并且脚本当前仅在您导航到脚本所在的页面时运行,我想做的是让它在每次加载页面时都运行脚本。我相信我必须在.htaccess文件中做这件事,我不确定如何做。

这是我当前的.htaccess文件

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}'.html -f 
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}'.php -f 
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} !^www'.giantnodes'.com [NC]
RewriteRule ^(.*)$ http://www.giantnodes.com/$1 [R=301,L]
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

您可以在每次运行请求的脚本之前使用auto_prepend_file来运行脚本。

可以在php.ini文件或.htaccess文件中设置。

对于.htaccess,您可以添加以下内容:

php_value auto_prepend_file "/path/to/your/file.php"