Forum Moderators: phranque
We use drupal for one of our websites. When clean URL module is activated, drupal adds the following lines to the .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
URL in the form http://example.com/user is supposed to be re-written by http://example.com/index.php?q=user
Instead, it is rewritten by http://example.com/index.php and the query string is somehow lost despite the QSA option.
This is how the rewrite log looks like
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (3) [perdir C:/Drupal/drupal5/] strip per-dir prefix: C:/Drupal/drupal5/user -> user
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (3) [perdir C:/Drupal/drupal5/] applying pattern '^(.*)$' to uri 'user'
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (2) [perdir C:/Drupal/drupal5/] rewrite 'user' -> 'index.php?q=user'
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (3) split uri=index.php?q=user -> uri=index.php, args=q=user
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (3) [perdir C:/Drupal/drupal5/] add per-dir prefix: index.php -> C:/Drupal/drupal5/index.php
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (2) [perdir C:/Drupal/drupal5/] strip document_root prefix: C:/Drupal/drupal5/index.php -> /index.php
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#121c7a0/initial] (1) [perdir C:/Drupal/drupal5/] internal redirect with /index.php [INTERNAL REDIRECT]
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#11ff920/initial/redir#1] (2) init rewrite engine with requested uri /index.php
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#11ff920/initial/redir#1] (1) pass through /index.php
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#11ff920/initial/redir#1] (3) [perdir C:/Drupal/drupal5/] strip per-dir prefix: C:/Drupal/drupal5/index.php -> index.php
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#11ff920/initial/redir#1] (3) [perdir C:/Drupal/drupal5/] applying pattern '^(.*)$' to uri 'index.php'
127.0.0.1 - - [04/May/2008:14:11:33 --0400] [example.local/sid#775780][rid#11ff920/initial/redir#1] (1) [perdir C:/Drupal/drupal5/] pass through C:/Drupal/drupal5/index.php
It looks like the rule parsing goes fine, but then, the query string is stripped. Why is that?
That is, if you called your code with /user?foo=bar and DID NOT use QSA, then ?"foo=bar" would be replaced by "q=user". If you DID use [QSA], then "q=user" would be appended to "?foo=bar" giving the query string "?foo=bar&q=user".
So, I doubt that [QSA] has anything to do with this. You code looks OK, though. Therefore, I would suggest trying to put some "echo" statements into your Drupal code, to see where and how the query string is being dropped.
As a last-ditch method, you could temporarily change the mod_rewrite code to do an external redirect, and then use a server headers tool to see if you're getting recursion or some other problem that results in the query string being dropped. I like the "Live HTTP Headers" add-on for Firefox/Mozilla browsers, but there are others, as well as some on-line server headers checkers. Be sure that whatever tool you use, it shows *all* headers and transactions, though -- some don't.
Be aware that in RewriteLog, query strings are "rarely mentioned." That is, just because the log says you're internally redirecting to a URL-path with no query string appended to it, that does not mean that there is no query string appended to that URL-path. Compare to a RewriteLog entry for a successful query-string rewrite if this is not clear.
Jim