1

In my Drupal sites, there are many "page not found" for modules/statistics/statistics.php recorded in the log ("Recent log messages" or /admin/reports/dblog). Many of them were accessed by the admininistrator in the record. The file exists, of course.

That seems strange to me. Why is it so?

Note the core statistics module (Ver.7.32) is enabled, and all the three options (access log, Count content views, Use Ajax to increment the counter) in its configuration are enabled.

[Description added]
In the Report page /admin/reports/dblog when I click the links modules/statistics/statistics.php in the Message part, I see (for TYPE: page not found) the LOCATION of http://MyHost/en/modules/statistics/statistics.php or alike, that is, path with the language prefix. My websites use the path-prefix-based i18n feature.

2
  • 1
    Did you make any changes in the .htaccess (or web server vhost) configuration?
    – AKS
    Commented Nov 4, 2014 at 4:14
  • No change in .htaccess. For the localhost, vhost is setup. For the other, it is on the shared-hosting server and is not virtual but real. Both of them show the same error message for admin. Commented Nov 4, 2014 at 9:21

2 Answers 2

3

If file exists, but Drupal still captures calls to it, it may mean one of few things:

  1. Obviously this happens if filename is misspelled in one place (request or filesystem) but not the other (or misspelled differently in both).

  2. As above, sometimes this happens when paths are (slightly) different.

  3. Path you see in your address bar and path your server use to test for file existence are not the same thing. May look the same, but may not, depends on your .htaccess, nginx.conf or whatever you use to control that.

  4. Language prefixes may break things. If file /sites/default/files/example.jpg exists, server may fail to find en/sites/default/files/example.jpg. If that's the case, and for any reason you can't fix broken code, you can try setup like this in your htaccess:

    RewriteCond %{REQUEST_FILENAME} ^(en|de|fr)/(.*)$ [NC]
    RewriteCond %2 -f
    RewriteRule ^(en|de|fr)/(.*)$ $2 [NC,QSA,L]
    

    Notice, I didn't test it. OP preferred to use %{DOCUMENT_ROOT}%{REQUEST_URI} instead of %{REQUEST_FILENAME} to deal with the potential dependencies on the environment/timing etc - that are implementation details beyond the scope of this site, I believe. The logic behind it is, line by line:

    1. Test if request filename contains one of the specified prefixes (should match your site's languages.

    2. Test if file without prefix (second regex group) is there, and really is a file.

    3. If so, rewrite request to remove language prefix.

    Apply this logic and you should be good. Actual implementation may vary, but logic you want is just that.

9
  • As far as I carefully checked, neither 1 nor 2 is the case. As for 3, I haven't manually edited .htaccess or nginx.conf or else to control the access, and so Drupal (and the default HTTP server) takes a full control of it. Commented Nov 4, 2014 at 9:59
  • 4 is the most suspicious. See the end of the question, where I have added a description. That is interesting - statistics.php is a core feature. Does this mean many (or all) Drupal servers that use path-prefix-based language feature experience this? All the modules used in my sites are I think fairly to extremely popular ones, except for my own, which does nothing at all with the statistics module (at least explicitly, or as far as I am aware). Commented Nov 4, 2014 at 9:59
  • 1
    @MasaSakano on nginx by default yes. See this question I asked on Server Fault for example. Also, googling "drupal language prefix file links" shows it is a problem in many modules.
    – Mołot
    Commented Nov 4, 2014 at 10:03
  • I see, but the server of my sites is Apache. The suggested keyword for googling is spot on, thank you! Now I shall create the symlink from en/modules/statistics/statistics.php and see what will happen. Hope nothing will break down or cause knock-on effects… Commented Nov 4, 2014 at 10:34
  • 1
    @MasaSakano I did my best to translate this to Apache. Haven't tested. See my updated answer
    – Mołot
    Commented Nov 4, 2014 at 10:41
3

There is a bug report for this @ https://www.drupal.org/node/2172871

A temporary fix available @ https://www.drupal.org/node/2172871#comment-10247397

No need to hack the core. Just add the below function in your theme or module.

/**
 * Implements hook_url_outbound_alter().
 *
 * Fix statistics path when i18n path prefix enabled
 * see: https://www.drupal.org/node/2172871
 */
function YOUR_THEME_OR MODULE_url_outbound_alter(&$path, &$options, $original_path) {
  if ($original_path === 'modules/statistics/statistics.php' && isset($options['prefix'])) {
    $options['prefix'] = '';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.