RewriteRule不重定向到指定的文件

时间:2015-10-27 22:05:43

标签: regex apache mod-rewrite

这是我的重写规则:

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]

这是一个满口的东西所以在尝试调试时没有帮助,但它基本上允许这样的URL:http://localhost/rest/v1/users/show/12345.json

我已经在线上使用正则表达式测试仪进行了测试,然后通过了。但是当我将它添加到我的配置文件时,它不会重定向并提供404消息,因为它试图在users文件夹的show文件夹中找到文件1234.json。

我的错误日志如下所示:

[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

我不确定错误日志中发生了什么,但看起来它通过了正则表达式?

任何人都知道为什么它可能不起作用?

1 个答案:

答案 0 :(得分:1)

您在/rest/目录中有此规则。请在规则模式中尝试使用此重写规则而不使用rest/

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