2012-12-15 46 views
-1

我的服务器上有一些现有的PHP代码。现在我想登录关于请求到我的服务器的完整信息。我不想对现有代码进行任何更改。我正在使用Apache mod_rewrite。我有一个示例PHP脚本,stats.php这看起来是这样的apache mod_rewrite收集请求信息

<?php 

    /*NOTE:This is peseudo code!!!*/ 
    open database connection 
    add serverinfo, referer info, script_name, arguments info to database 
    change characters in request from UTF16 to UTF 8. 

    //Call header function for redirection 
    $str = Location : $_SERVER["REQUEST_URI"] 
    header ("$str"); 

?> 

在httpd.conf文件

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{REQUEST_URI} !/stats\.php 
RewriteCond %{REQUEST_URI} !\/favicon\.php 
RewriteRule ^/(.*)$  /stats.php?$1 [L] 
RewriteLog "logs/error_log" 
RewriteLogLevel 3 
</IfModule> 

的问题是,恐怕这未必是最好的搜索引擎优化的角度和也可能是越野车。有没有更好的方法来做到这一点?例如,我可以使用脚本访问access_log文件吗?

+1

这是真正的PHP在使用吗?因为没有任何工作,因为它是不正确的语法。 –

+0

@cryptic,它的语法不正确。它被认为是伪代码。我会在文中说清楚。 – user763410

回答

0

比方说,如果你去http://your-domain.com/some-page.html,你会得到一个循环:用请求的URI /some-page.html

  • mod_rewrite的

    1. 浏览器联系人服务器重写URI来/stats.php?some-page.html
    2. 统计。 php做它的事情,然后重定向浏览器到/some-page.html
    3. 浏览器联系人服务器与重新追求URI /some-page.html
    4. 重复开始,#2

    你需要做的,而不是与Location:头响应什么是阅读some-page.html文件的内容,并返回给浏览器,基本上是“代理”的要求为浏览器。因此浏览器不会重定向。

    至于如何做到这一点在PHP中,有大量的谷歌结果,甚至大量的answers on Stack Overflow

  • +0

    你正在写。这是我想要做的。 – user763410

    +0

    我想我应该做什么。我做了以下操作 1)将一个自定义的logformat添加到httpd.conf文件中。 2)增加了一个customLog dirctive。输出到stats.php。 3)stats.php负责将代码添加到数据库。 – user763410

    +0

    @ user763410,您应该将其作为您自己的单独答案发布。 – Charles

    0

    我想我应该做什么。我做了以下操作:

    1)将一个自定义的logformat添加到httpd.conf文件中。

    2)增加了一个customLog dirctive。输出到stats.php。

    3)stats.php负责将代码添加到数据库。