我有一个包含以下规则的.htaccess文件
# replace 'RewriteBase' with current working folder
# put '<base href="/">' in <head> if you are in the root folder
# put '<base href="/foldername/">' in <head> if you are in a subfolder of the root
Options +FollowSymLinks
RewriteEngine On
RewriteBase /pretty-urls
# Remove slash if file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1 [R=301,L]
# Redirect to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ user.php?u=$1 [NC]这基本上是将以下任何一个URLS、www.mysite.com/about.php、www.mysite.com/about和www.mysite.com/about/转换和重定向到www.mysite.com/about,还应该允许我编写www.mysite.com/user/john,但会抛出一个内部服务器错误和一个500。
我不知道出了什么问题,代码是基于这个( 怎么.?虚空URL &忽略带有.PHP的.htaccess扩展 )
我的php如下所示
foreach ( $users as $user ) {
echo '<p><a href="user/'.$user->username.'">'.$user->username.'</a></p>';
}任何帮助都是非常感谢的,谢谢。
编辑: Apache错误日志显示
[Fri Sep 27 14:26:26.539589 2013] [core:error] [pid 2276:tid 1680] [client ::1:60023] AH00124: 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., referer: http://localhost/pretty-urls/users正如建议的那样,我删除了[NC]标志并添加了[L]标志,但同样的错误仍然存在。
发布于 2013-09-27 14:16:50
错误Request exceeded the limit of 10 internal redirects通常是由一个重写规则引起的,该规则与原始url以及重写的url匹配。L标志只会停止当前周期的重写,但是当apache再次通过.htaccess推送请求时,这不会停止这些错误的内部重定向。
在我自己的本地主机上重新创建它时,我注意到问题在于将.php添加到您的url中的规则。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]在我的例子中,%{REQUEST_FILENAME}包含到document_root/user的文件路径。您可以测试document_root/user.php是否是一个文件(它是一个文件),然后将.php添加到url中,这将导致/user/john/.php。我认为这个问题可以解决,把你的文件移到一个子目录,这样虚拟的url就永远不会匹配你的文件夹中的文件或目录。
您可以将规则更改为如下内容,但我不确定这是否会完全消除问题:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?(.*)$ $1.php?q=$2 [L]这将将link.url/test/qwer重写为test.php?q=qwer,link.url/test重写为test.php?q=。
您为user.php进行内部重写的规则应移至“一般”规则之上,并应更改为:
RewriteRule ^user/(.*)/?$ user.php?u=$1 [NC,L]这将将link.url/user/john/重写为user.php?u=john。
与往常一样,请参见文献资料。要正确调试.htaccess,请将LogLevel alert rewrite:trace3放入httpd.conf并重新启动服务。这将显示如下所示的线条,为您提供了所发生的事情的线索:
[rewrite:trace1] [pid 4800:tid 1532] mod_rewrite.c(468): [client ::1:49451] ::1 - - [localhost/sid#3ecb48][rid#12b1a88/initial/redir#2] [perdir C:/wamp/www/] internal redirect with /user/john/.php.php.php [INTERNAL REDIRECT]https://stackoverflow.com/questions/19050516
复制相似问题