Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite, drupal, and site stats

Drupal's mod_rewrite rules prevent me from viewing site stats

         

mike3k

1:50 am on Feb 7, 2005 (gmt 0)

10+ Year Member



I have several Drupal sites with mod_rewrite rules for clean URLs, and in two of them I also have rules to rewrite PHP-Nuke URLs to Drupal.

On my web host (DreamHost), stats are viewed as [domainname...] However, I can't figure out how to prevent the rewrite rules from catching the stats URL and redirecting it to drupal.

The basic rule which converts a 'clean' URL into a query string is:

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I tried adding the following and several variations as the first rule, but I can't get one to work:

RewriteRule ^stats(.*) stats$1 [NC,L]

jdMorgan

2:56 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mike3k,

Welcome to WebmasterWorld!

The first rule you posted doesn't seem to apply, since the /stats directory exists (the rule should fail on the !-d test). Are there any others that might be causing this?

The quick fix is to precede any rules that might be interfering with:


RewriteRule ^stats - [L]

which says, "if the local URL-path begins with '/stats' then do nothing, and stop processing rewrite rules." It therefore bypasses any rules that follow it if the request is for /stats.

Note that the leading slash is stripped before testing by RewriteRule in an .htaccess context. If your code is in httpd.conf, use:


RewriteRule [b]^/s[/b]tats - [L]

instead.

Jim

mike3k

3:14 am on Feb 7, 2005 (gmt 0)

10+ Year Member



That works.

Actually there's no stats directory - the server redirects it to Analog, which is actually outside the main web directory, probably from httpd.conf which gets overridden by my .htaccess.