我有一个.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]
这基本上会转换和重定向以下任何 URL、www.mysite.com/about.php
和www.mysite.com/about
towww.mysite.com/about/
并且www.mysite.com/about
还应该允许我编写www.mysite.com/user/john
,但会抛出内部服务器错误加上 500。
我不知道出了什么问题,代码基于此(How-to?Vanity URL & ignore .PHP extension with .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]
标志,但同样的错误仍然存在。