RewriteRule leitet nicht an die angegebene URL weiter

468
Adam Carter

Hier ist meine Regel zum Umschreiben:

RewriteRule ^rest/v(?:[0-9.]+)/((?:[A-Za-z]+)/(?:[A-Za-z]+)(?:/(?:[A-Za-z0-9])+))?\.(json)$ https://localhost/rest/v1/index.php?url=$1&type=$2 [QSA,NC,L] 

Es ist so etwas wie ein Bissen, hilft also nicht beim Debuggen, aber im Grunde erlaubt es eine URL wie diese: http: //localhost/rest/v1/users/show/12345.json

Ich habe es in einem Regex-Tester online getestet und es besteht. Wenn ich sie jedoch meiner Konfigurationsdatei hinzufüge, leitet sie nicht um und gibt eine 404-Nachricht aus, wenn sie versucht, die Datei 1234.json im show-Ordner des Benutzerordners zu finden.

Mein Fehlerprotokoll sieht so aus:

[Tue Oct 27 21:55:16.345721 2015] [mpm_prefork:notice] [pid 4172] AH00169: caught SIGTERM, shutting down [Tue Oct 27 21:55:21.005180 2015] [suexec:notice] [pid 4318] AH01232: suEXEC mechanism enabled (wrapper: /Applications/XAMPP/xamppfiles/bin/suexec) [Tue Oct 27 21:55:22.001398 2015] [lbmethod_heartbeat:notice] [pid 4319] AH02282: No slotmem from mod_heartmonitor [Tue Oct 27 21:55:22.001761 2015] [auth_digest:notice] [pid 4319] AH01757: generating secret for digest authentication ... [Tue Oct 27 21:55:22.014532 2015] [mpm_prefork:notice] [pid 4319] AH00163: Apache/2.4.10 (Unix) OpenSSL/1.0.1j PHP/5.6.3 mod_perl/2.0.8-dev Perl/v5.16.3 configured -- resuming normal operations [Tue Oct 27 21:55:22.014627 2015] [core:notice] [pid 4319] AH00094: Command line: '/Applications/XAMPP/xamppfiles/bin/httpd -E /Applications/XAMPP/xamppfiles/logs/error_log -D SSL -D PHP' [Tue Oct 27 21:55:30.096376 2015] [rewrite:trace3] [pid 4323] mod_rewrite.c(475): [client ::1:50020] ::1 - - [localhost/sid#101019668][rid#10087d4a0/initial] [perdir /Applications/XAMPP/xamppfiles/htdocs/rest/] add path info postfix: /Applications/XAMPP/xamppfiles/htdocs/rest/v1/users -> /Applications/XAMPP/xamppfiles/htdocs/rest/v1/users/show/12345.json [Tue Oct 27 21:55:30.096499 2015] [rewrite:trace3] [pid 4323] mod_rewrite.c(475): [client ::1:50020] ::1 - - [localhost/sid#101019668][rid#10087d4a0/initial] [perdir /Applications/XAMPP/xamppfiles/htdocs/rest/] strip per-dir prefix: /Applications/XAMPP/xamppfiles/htdocs/rest/v1/users/show/12345.json -> v1/users/show/12345.json [Tue Oct 27 21:55:30.096507 2015] [rewrite:trace3] [pid 4323] mod_rewrite.c(475): [client ::1:50020] ::1 - - [localhost/sid#101019668][rid#10087d4a0/initial] [perdir /Applications/XAMPP/xamppfiles/htdocs/rest/] applying pattern '^rest/v(?:[0-9.]+)/((?:[A-Za-z]+)/(?:[A-Za-z]+)(?:/(?:[A-Za-z0-9])+))?\\.(json)$' to uri 'v1/users/show/12345.json' [Tue Oct 27 21:55:30.096521 2015] [rewrite:trace1] [pid 4323] mod_rewrite.c(475): [client ::1:50020] ::1 - - [localhost/sid#101019668][rid#10087d4a0/initial] [perdir /Applications/XAMPP/xamppfiles/htdocs/rest/] pass through /Applications/XAMPP/xamppfiles/htdocs/rest/v1/users 

Ich bin nicht wirklich sicher, was im Fehlerprotokoll vorgeht, aber es sieht so aus, als würde es die Regex weitergeben?

Weiß jemand, warum es nicht funktioniert?

0

1 Antwort auf die Frage

0
RobertL

Ein Grund, warum das Muster nicht passt, weil das Muster rest/am Anfang aussieht und der URI mit beginnt v1.

Zu prüfen ist noch, dass der RewriteRule-Konfigurationstext von der in den Protokollen angezeigten Regel abweicht. Die Quellregel enthält \.jsonam Ende und die Logfile-Regel wird angezeigt \\.json.

Entfernen Sie also möglicherweise das "rest /" in Ihrem Muster für die Neuschreibungsregel und versuchen Sie es erneut. Wenn es immer noch nicht funktioniert, stellen Sie sicher, dass Sie keinen doppelten Backslash vor haben .json.