繁体   English   中英

PHP:htaccess:重写规则在非现有页面上获得500 ERROR

[英]PHP: htaccess: Rewrite rules are getting 500 ERROR on non existing pages

我有一个网站,基本上使用RewriteRule隐藏.php,并允许脚本通过斜杠确定参数。

例如: http//www.dealhandler.com/deals/san-jose/Living%20Social/233102

脚本是Deals.php,它接受San-Jose,Living Social和Deal ID之类的参数。

这是我的.htaccess:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^dealhandler.com 
RewriteRule ^(.*)$ http://www.dealhandler.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ $1.php$2 [L,QSA]

问题:如果访问者输入了根级别没有脚本的无效网址,则会出现500 ERROR。

示例: http : //www.dealhandler.com/idontexist我将得到:

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.

有没有办法保留当前功能,但如果根目录文件不存在,足够聪明以停止和重定向?

乍一看,似乎它在找不到指定名称的文件时无限添加.php。 如果打开调试日志记录,您应该可以轻松确认。

您最好的选择是:1)只将.php附加到尚未以.php结尾的字符串中,因此它只会发生一次或2)在应用规则之前检查潜在的新.php文件名是否存在于另一个条件中完全没有

尝试在RewriteRule之前添加此权限:

RewriteCond %{REQUEST_URI} !^/[^/]+\.php

未映射到有效php文件的请求(如idontexist.php)应仅返回404。

这里应该避免无限循环: 首先测试它是否不是文件或目录,如果以“ php”结尾,然后立即停止。 如果不是规则继续并尝试自己的测试:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^dealhandler.com 
RewriteRule ^(.*)$ http://www.dealhandler.com/$1 [R=301,L]

# if it's not a file...
RewriteCond %{REQUEST_FILENAME} !-f
# ... and it's not a dir...
RewriteCond %{REQUEST_FILENAME} !-d
# ...and it ends by "php" then stop:
RewriteRule (.*)\.php$ - [L]

# if it's not a file...
RewriteCond %{REQUEST_FILENAME} !-f
# ... and it's not a dir...
RewriteCond %{REQUEST_FILENAME} !-d
# ...rewrite it to php:
RewriteRule ^([^/]*)(.*)$ $1.php$2 [L,QSA]

检查你的../apache/conf/httpd.conf并寻找:

#LoadModule rewrite_module modules/mod_rewrite.so

如果井号(#)作为第一个字母出现,请将其删除,保存并重新启动服务器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM