简单的mod重写重定向不起作用

时间:2011-11-21 10:10:57

标签: apache mod-rewrite

您好我正在尝试编写一个mod重写代码,将/ example重定向到/example.php。代码看起来应该正常工作但不是:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)/$ /$1.php

错误日志文件:

  [Mon Nov 21 04:13:27 2011] [error] [client 109.149.215.195] 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.
  [Mon Nov 21 04:13:31 2011] [error] [client 109.149.215.195] 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.
  [Mon Nov 21 08:26:23 2011] [error] [client 109.149.215.195] Negotiation: discovered file(s) matching request: /var/chroot/home/content/86/8128686/html/college (None could be negotiated).

  [Wed Nov 23 16:33:55 2011] [alert] [client 109.149.215.195] /var/chroot/home/content/86/8128686/html/.htaccess: RewriteLog not allowed here

  [Wed Nov 23 16:43:23 2011] [error] [client 109.149.215.195] File does not exist: /var/chroot/home/content/86/8128686/html/missing.html
  [Wed Nov 23 16:43:39 2011] [error] [client 109.149.215.195] Negotiation: discovered file(s) matching request: /var/chroot/home/content/86/8128686/html/index (None could be negotiated).
  [Wed Nov 23 16:43:39 2011] [error] [client 109.149.215.195] File does not exist: /var/chroot/home/content/86/8128686/html/missing.html
  [Thu Nov 24 02:46:47 2011] [error] [client 69.58.178.58] Directory index forbidden by Options directive: /var/chroot/home/content/86/8128686/html/uploads/
  [Thu Nov 24 02:46:47 2011] [error] [client 69.58.178.58] File does not exist: /var/chroot/home/content/86/8128686/html/missing.html

提前致谢

1 个答案:

答案 0 :(得分:1)

首先,这是我的建议:

请尝试使用RewriteLog指令:它可以帮助您找出此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

然后是解决方案:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)$ /$1.php [QSA,L]

告诉我它是否有效。