To content | To menu | To search

Tag - apache

Entries feed - Comments feed

Thursday 26 June 2008

Apache and mod_rewrite to subdirectories

Naneau just poke me with a little problem he had with mod_rewrite when trying to rewrite to a subdirectory. Imagine you've got the following setup:

  • Apache's document root is /document_root/
  • You application's bootstrap is /document_root/public/index.php

You could come to the following rewrite rules quite easily:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php/$1 [L]

And you'd be horribly wrong.

The problem here is that when you hit / on your server, mod_rewrite will populate %{REQUEST_FILENAME} it to /document_root/, which obviously fails the !-d rewrite condition. By the magic of DirectoryIndex, you'll eventually hit /index.html (or whatever your directory index is set to), and there we go for another rewrite magic. At this point, things get a little messy, and if you're like naneau, you'll end up crying while rolling on the floor and calling for help on irc (that's quite a set of hard things to achieve at the same time).

The solution is not that simple, and actually, I've not found a fully satisfying solution yet (although naneau is satisfied with the partial solution). The quick hack is to simpy remove the !-d condition. The obvious drawback is that any existing directory will get rewritten, but you'll be able to access the files inside it. I'm still working on a more complete solution, but as it's not my main concerne for the moment, it'll wait a bit (unless someone posts a solution in the comments).

Sunday 1 October 2006

Edgy Eft, Dotdeb, php5-pdo-mysql, et moi

Bon voilà, ce n'est un secret pour personne, j'ai mis à jour ma Dapper en Edgy, et après avoir laborieusement activé l'accélération 3D de ma carte graphique, je me suis attelé à la reconstitution de mon environnement de développement favori: LAMP5. Cet enrivonnement comprend de plus l'extension PDO Mysql, très utile dans le cadre de l'utilisation du Zend Framework :-) Seulement voilà, Edgy propose un paquet php5 plus à jour que celui de dotdeb, ce qui empêche l'installation du paquet php5-pdo-mysql de dotdeb. Ayant mieux à faire qu'installer pdo_mysql via pear, j'ai décidé d'apprendre à me servir un peu d'APT, et je me propose de vous faire part de mes conclusions. Commençons par le commencement, le message d'erreur:

Les paquets suivants contiennent des dépendances non satisfaites :
  php5-pdo-mysql: Dépend: phpapi-20041225
                  Dépend: php5-common (= 5.1.6-0.dotdeb.2) mais 5.1.6-1ubuntu1 devra être installé
E: Paquets défectueux

Il suffit donc de spécifier à APT que nous souhaitons utiliser la version 5.1.6-0.dotdeb.2 du paquet php5-common. Rien de plus simple ! Cela se passe dans /etc/apt/preferences:

Package: php5-common
Pin: version 5.1.6-0.dotdeb.2
Pin-Priority: 1001

Et comme libapache2-mod-php5 dépend également de php5-common, il va nous falloir faire de même:

Package: libapache2-mod-php5
Pin: version 5.1.6-0.dotdeb.2
Pin-Priority: 1001

Voilà, désormais APT n'installera que la version 5.1.6-0.dotdeb.2 de ces deux paquets, quoiqu'il arrive. Un simple apt-get install php5-pdo-mysql suffit désormais pour que tout rentre dans l'ordre !

A noter: le tutoriel qui m'a tout appris.