mod_rewrite 总是给出 10 个内部重定向并且失败

mod_rewrite 总是给出 10 个内部重定向并且失败

我有一个简单的 .htaccess,由于某种原因无法正确重定向:

RewriteEngine on
RewriteBase /
RewriteRule ^.*$ /test.php [L]

有一个日志条目:

[Tue Nov 16 17:04:12 2010] [error] [client 213.141.155.85] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Tue Nov 16 17:04:12 2010] [debug] core.c(3053): [client 213.141.155.85] r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /test.php
[Tue Nov 16 17:04:12 2010] [debug] core.c(3059): [client 213.141.155.85] redirected from r->uri = /blabla

我尝试访问的 URL 是 /blabla

看起来重写正确,但是 [L] 选项不知为何不起作用。这是怎么回事?

虚拟主机配置如下:

<VirtualHost *:80>
ServerName www.mx-key.ru
ServerAlias mx-key.ru www.mx-key.ru
ServerAdmin [email protected]
DocumentRoot /home/mxkey/mx-key.ru/www
DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml
ErrorLog /home/mxkey/mx-key.ru/logs/httpd_error.log
CustomLog /home/mxkey/mx-key.ru/logs/httpd_access.log "%v %h %l %u %t \"%r\" %>s %b"
LogLevel Debug
<IfModule mod_fastcgi.c>
        Options +ExecCGI
        FastCgiExternalServer /home/mxkey/mx-key.ru/www/php-fpm.handler -socket /home/mxkey/php-fpm.sock -idle-timeout 600
        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php-fpm.handler
</IfModule>
</VirtualHost>

答案1

您还需要指定RewriteCond- 您的RewriteRule始终匹配所有内容(因为^.*$)。请看这里:

您需要排除 的目标RewriteRule,即/test.php

类似这样的事情应该可以工作:

RewriteCond %{REQUEST_URI} !^/test.php$

其含义类似于“仅当请求 URI 不以 /test.php 开头时才重写”。

相关内容