-1

I have some existing PHP code on my server. Now I want log-in complete information about requests that come to my server. I don't want to make any changes to existing code. I am using apache mod_rewrite for this. I have a sample php script,stats.php which looks something like this

<?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");

?>

In httpd.conf file

<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>

The problem is, I am afraid this may not be best from SEO perspective and also may be buggy. Are there any better ways to do this? For example, can I use a script to the access_log file?

user763410
  • 502
  • 6
  • 22

2 Answers2

0

Say for example, if you go to http://your-domain.com/some-page.html, you'll get a loop:

  1. Browser contacts server with request URI /some-page.html
  2. mod_rewrite rewrites the URI to /stats.php?some-page.html
  3. The stats.php does its thing, then redirects the browser to /some-page.html
  4. Browser contacts server with request URI /some-page.html
  5. repeat starting at #2

What you need to do instead of responding with the Location: header is read the contents of the some-page.html file and return that to the browser, essentially "proxying" the request for the browser. The browser therefore doesn't get redirected.

As for how to do that in php, there's plenty of google results or even plenty of answers on Stack Overflow.

Community
  • 1
  • 1
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • you are write. This is what I want to do. – user763410 Dec 15 '12 at 07:40
  • I figured what I should do. I did the following 1) Add a custom logformat to httpd.conf file. 2) Added a customLog dirctive. Piped the output to stats.php. 3) stats.php takes care of adding the code to database. – user763410 Dec 15 '12 at 07:44
  • @user763410, you should post that as your own separate answer. – Charles Dec 15 '12 at 08:14
0

I figured what I should do. I did the following

1) Add a custom logformat to httpd.conf file.

2) Added a customLog dirctive. Piped the output to stats.php.

3) stats.php takes care of adding the code to database.

user763410
  • 502
  • 6
  • 22