mod_rewrite / htaccess重定向问题! (递归限制)

时间:2012-01-31 17:33:03

标签: php apache mod-rewrite

我正在尝试创建我的mod_rewrite文件,以便在查看文件时基本上删除所有.php扩展名。

这是我的.htaccess:

RewriteEngine On
DirectoryIndex index.php
ErrorDocument 404 /errors/404.php
ErrorDocument 403 /errors/403.php
ErrorDocument 500 /errors/500.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

现在这是我在尝试随机名称时从我的apache日志中得到的错误:

[Tue Jan 31 17:26:05 2012] [error] [client 127.0.0.1] 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 Jan 31 17:26:05 2012] [debug] core.c(3112): [client 127.0.0.1] r->uri = /aboutasdfoi.php.php.php.php.php.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi.php
[Tue Jan 31 17:26:05 2012] [debug] core.c(3118): [client 127.0.0.1] redirected from r->uri = /aboutasdfoi

我如何解决这个问题?感谢

1 个答案:

答案 0 :(得分:2)

要隐藏.php扩展名,请使用以下代码:

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [R=301,L,NC]

# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]