Apache / Rewrite - (Brain)Bug?
globe
- webserver
n'abend,
ich habe eben die Struktur eines meiner Projekte umgestellt. Dabei ist das Script, welches für jeden eingehenden Request angesprochen werden soll, (berechtigterweise) aus dem DocumentRoot verschwunden. Die neue Struktur sieht folgendermaßen aus:
/my/path/htdocs << nur statischer Kram
/my/path/foobar << hier liegt die sofware
/my/path/foobar/main.php << das script, welches die Requests abfertigen soll
Das Problem tritt auf meinem MacBook (Mac OS X 10.5.1) mit Apache 2.2.6 (nein, nich der mitgelieferte - die MacPorts Variante) auf. Ich habe zwei verschiedene Vorfälle, wobei der irriterende in beiden Ansätzen auftaucht. Hier ein Auszug aus dem Rewrite-Log
(2) init rewrite engine with requested uri /my/path/foobar/main.php
(1) pass through /my/path/foobar/main.php
(3) [perdir /my/path/htdocs/] add path info postfix: /my/path/htdocs/my -> /my/path/htdocs/my/path/foobar/main.php
Was bitte soll das »/my/path/htdocs/my/path/foobar/main.php« werden? Ich kann ja erahnen, dass das passiert, weil Apache das Gefühl hat ich will hier "relativ" zum DocumentRoot arbeiten - was ich aber eigentlich nicht will. RewriteBase bringt mir an dieser Stelle auch nichts, da ich damit nur das virtuelle Verzeichnis, nicht aber das psyische Verzeichnis manipulieren kann. Höher als DocumentRoot scheine ich damit auch nicht zu kommen.
Details zu den beiden Ansätze sind in den folge-Posts »Fall: Endlosschleife« und »Fall: Nicht gefunden« zu finden.
Hat jemand ne Idee was ich hier verbocke?
weiterhin schönen abend...
##########################################
##########################################
<Directory "/my/path/htdocs">
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride None
RewriteEngine On
# route / to handler
RewriteRule ^/?$ /my/path/foobar/main.php [L]
# routy anything but real files to handler
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^/?(styles|ads|js)
# try to take out that recursion
RewriteCond %{REQUEST_FILENAME} !main.php
RewriteCond %{REQUEST_FILENAME} !/?my/path/foobar/main.php
RewriteRule ^(.*)$ /my/Rodney/Projekte/Lakeparty/branches/templating/foobar/main.php [L]
</Directory>
##########################################
##########################################
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (2) init rewrite engine with requested uri /
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (1) pass through /
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/ ->
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (3) [perdir /my/path/htdocs/] applying pattern '^/?$' to uri ''
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (2) [perdir /my/path/htdocs/] rewrite '' -> '/my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#931c50/initial] (1) [perdir /my/path/htdocs/] internal redirect with /my/path/foobar/main.php [INTERNAL REDIRECT]
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (2) init rewrite engine with requested uri /my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (1) pass through /my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] add path info postfix: /my/path/htdocs/my -> /my/path/htdocs/my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/my/path/foobar/main.php -> my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] applying pattern '^/?$' to uri 'my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] add path info postfix: /my/path/htdocs/my -> /my/path/htdocs/my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/my/path/foobar/main.php -> my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (3) [perdir /my/path/htdocs/] applying pattern '^(.*)$' to uri 'my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/my' pattern='!-d' => matched
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/my' pattern='!-f' => matched
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/my' pattern='!^/?styles' => matched
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/my' pattern='!main.php' => matched
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/my' pattern='!my/path/foobar/main.php' => matched
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (2) [perdir /my/path/htdocs/] rewrite 'my/path/foobar/main.php' -> '/my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:26:26 +0100] [my.vhost/sid#8aec30][rid#9369a0/initial/redir#1] (1) [perdir /my/path/htdocs/] internal redirect with /my/path/foobar/main.php [INTERNAL REDIRECT]
##########################################
##########################################
<Directory "/my/path/htdocs">
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride None
RewriteEngine On
# avoid recursive crap resulting in a 500
RewriteRule ^/?my/path/foobar/main.php$ - [L]
# route any call to a (physically) inexisting file to the handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^/?(styles|ads|js)
RewriteRule ^(.*)$ /my/path/foobar/main.php [L]
</Directory>
##########################################
##########################################
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (2) init rewrite engine with requested uri /asdasd
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (1) pass through /asdasd
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/asdasd -> asdasd
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (3) [perdir /my/path/htdocs/] applying pattern '^/?my/path/foobar/main.php$' to uri 'asdasd'
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/asdasd -> asdasd
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (3) [perdir /my/path/htdocs/] applying pattern '^(.*)$' to uri 'asdasd'
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/asdasd' pattern='!-f' => matched
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (4) [perdir /my/path/htdocs/] RewriteCond: input='/my/path/htdocs/asdasd' pattern='!^/?(styles|ads|js)' => matched
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (2) [perdir /my/path/htdocs/] rewrite 'asdasd' -> '/my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#939c50/initial] (1) [perdir /my/path/htdocs/] internal redirect with /my/path/foobar/main.php [INTERNAL REDIRECT]
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (2) init rewrite engine with requested uri /my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (1) pass through /my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (3) [perdir /my/path/htdocs/] add path info postfix: /my/path/htdocs/my -> /my/path/htdocs/my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (3) [perdir /my/path/htdocs/] strip per-dir prefix: /my/path/htdocs/my/path/foobar/main.php -> my/path/foobar/main.php
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (3) [perdir /my/path/htdocs/] applying pattern '^/?my/path/foobar/main.php$' to uri 'my/path/foobar/main.php'
127.0.0.1 - - [10/Jan/2008:14:48:54 +0100] [my.vhost/sid#822630][rid#93f358/initial/redir#1] (1) [perdir /my/path/htdocs/] pass through /my/path/htdocs/my
##########################################
##########################################
[Thu Jan 10 14:48:54 2008] [error] [client 127.0.0.1] File does not exist: /my/path/htdocs/my
Hallo globe, Hallo allerseits,
Zur Info für's Archiv, wir hatten's gerade im Chat davon:
mod_rewrite kann nur im Server-Kontext (Zentrale Config, <VirtualHost>) nach Dateinamen umschreiben, im Verzeichnis-Kontext (<Directory>, <Location>, .htaccess) kann man nur nach URIs umschreiben.
Viele Grüße,
Christian
n'abend,
mod_rewrite kann nur im Server-Kontext (Zentrale Config, <VirtualHost>) nach Dateinamen umschreiben, im Verzeichnis-Kontext (<Directory>, <Location>, .htaccess) kann man nur nach URIs umschreiben.
Tja, klassischer Fall von BrainBug :)
Der Hinweis hat jedoch geholfen... funktioniert nun alles wie es soll.
Das einzig dämliche ist nun, dass bei jedem Request "Unmengen" an Rewrite-Direktiven durchgearbeitet werden müssen...
Ich habe nun alle Rewrites auf die vHost-Ebene verschoben. Dummerweise sind nun meine Alias und RewriteAlias Direktiven "für'n Arsch". Diese Direktiven habe ich kurzfristig ebenfalls in Rewrites umgebaut, auch wenn ich das irgendwie für nicht so toll halte (Alias und Rewrite sind halt unterschiedliche Perfomance-Klassen)... :/
weiterhin schönen abend...