.htaccess rewrite rules

Memo: if you use multiple rewrite rules in your .htaccess file, remember that each RewriteRule must follow the necessary RewriteCond, e.g. you can not pack all rules. Thus, this doesn’t work:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^/]+)/([^/]+)$ index.php?jid=$1&mode=$2 [L,QSA]
  RewriteRule ^(.*)$ index.php?jid=$1 [L,QSA]

while this works smoothly.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?jid=$1&mode=$2 [L,QSA]

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

Of course I stumbled upon this while hacking at my jabber presence agent.

Pubblicato da

Stefano Costa

Archaeologist, I study the Late Antique and Early Medieval/Byzantine period on the northern side of the Mediterranean, focusing on pottery usage patterns. I'm also involved in open source and open knowledge communities, like OSGeo, the IOSA project and the Open Knowledge Foundation.

Rispondi