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

发布于 2024-12-29 20:01:43 字数 2087 浏览 0 评论 0原文

我正在尝试创建 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

我该如何修复它?谢谢

I'm trying to create my mod_rewrite file so that basically all of the .php extensions are removed when you view a file.

Here's my .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]

Now here's the error i get from my apache log when trying a random name:

[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

How do i go about fixing it? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2025-01-05 20:01:43

要隐藏 .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]

To hide .php extension use this code:

# 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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文