我有一個.htaccess
文件下列規則結合的.htaccess規則:刪除擴展和重寫URL變量
# 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]
這基本上轉換和重定向以下任一網址,www.mysite.com/about.php
,www.mysite.com/about
和www.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]
標誌,但同樣的錯誤仍然存在。
嘗試調試使用Apache日誌你重寫劇本,像這樣: http://serverfault.com/questions/135694/mod-rewrite-settings-causes-server-to-throw-http-500-errors-404- –
謝謝,我檢查了答案並更新了我的帖子,但還是500錯誤。 –
你在''extensionless url''規則中缺少']'。 – anubhava