[drupal-devel] [bug] .htaccess - issue with rewriting to cgi's

davek drupal-devel at drupal.org
Mon Aug 8 03:54:41 UTC 2005

Issue status update for 
Post a follow up: 

 Project:      Drupal
 Version:      4.6.0
 Component:    other
 Category:     bug reports
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  davek at davekaufman.net
 Updated by:   davek at davekaufman.net
-Status:       active
+Status:       patch (code needs review)
 Attachment:   http://drupal.org/files/issues/htaccess_3.patch (375 bytes)

The patch in question.

davek at davekaufman.net

Previous comments:

Mon, 08 Aug 2005 03:43:25 +0000 : davek at davekaufman.net

After attempting to create a custom rewrite rule that had nothing to do
with drupal, I noticed that the following rules in the default
.htaccess file were being too greedy and seemingly matching every URL

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

as near as I can determine, the problem arose from the fact that my
custom rewrite was dealing with a cgi. Specifically, I was attempting
to rewrite a URL of the form:


to the form


but it wasn't working.

After beating my head against it for a couple hours, I discovered that
mod_rewrite can be set to log what it's doing, which is when I found
the overly greedy rules.

The fix (or at least the fix I discovered) is to add the following line
to that section of the .htaccess file:

 RewriteCond %{REQUEST_FILENAME} !.*cgi-bin.*

which says, in essence, "any URI that contains the string 'cgi-bin' is
exempt from the following RewriteRule"

I've included a "patch" containing this change.  Rewriting URLs for
cgi's is a pretty common thing to do, can someone please verify this

More information about the drupal-devel mailing list