.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 work in Liguria where I live with my family. In my studies, I spent most of my energies with 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 initiatives.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.