Skip to content

Using the Wp-Dstats2 plugin with .htaccess rewriting rules

18 days ago I’ve installed the Wp-Dstats2-Plugin for Worpress. This plugin generates some statistics, e.g. ‘last 10 comments’, ‘visitors’ or – to me most interesting – ‘referrers’.

The data that gets accumulated by that script is quite interesting. I just recently noticed that it does not store the page that was referred (i.e. a single post on my weblog).

Searching for the cause of that behavior I noticed that Wp-Dstats2 will only work correctly in that regard without using rewriting rules (see Options -> Permalinks in your admin-interface). At least that’s my conclusion.

So I fiddled about a bit and came up with a hack that at least does the job for me. I’d guess it will be helpful to other users of Wordpress, too. So here it goes:

  1. Open wp-content/plugins/wp-dstats-advanced.php – or whereever you placed your wp-dstats-advanced.php – in an editor.
  2. Search for the lines that say
    if ($page == NULL) {
            $page = $id;
            if ($page < 1) {
                $page = 0;
            }
  3. Change this to
    if ($page == NULL) {
            $page = $id;
            if ($page < 1) {
                $page =  dstats2_idFromRewriting();
            }
  4. Put the line include 'wp-dstats-rewrite.php'; at the beginning of that file
  5. Download wp-dstats-rewrite.php.txt. Cut the ‘.txt’ and put the file in the directory of wp-dstats-advanced.php.Download wp-dstats-rewrite.txt. Change the ‘.txt’ to ‘.php’ and put the file in the directory of wp-dstats-advanced.php.

My solution uses the name, year, month and dayofmonth parameters that are given (invisibly) to the Wordpress-script via the URL. But it can be adapted quite easily. Have a look at ./wp-blog-header.php and compare this with wp-dstats-rewrite.php to get an idea.

Verwandte Artikel

{ 3 } Comments

  1. Aliosha | 2004/8/13 at 01:50 | Permalink

    I would REALLY like to use your hack in my installation of WP, but it seems that your file wp-dstats-rewrite.php.txt does not exist!
    Sigh…

  2. Steffen | 2004/8/13 at 02:47 | Permalink

    Hello Aliosha,

    Sorry, the file-extension ‘.php.txt’ caused the script to be executed. ;-)

    So it WAS there, just not downloadable. I renamed it by leaving out the ‘.php’. Now it does work.

    Thanks for letting me know!

  3. MtDewVirus | 2004/9/28 at 04:39 | Permalink

    Awesome! Nice work.

Post a Comment

Your email is never published nor shared. Required fields are marked *