htaccess重写给我500错误?

时间:2010-10-14 19:32:04

标签: php .htaccess url rewrite

我有这个网址,我想要友好,使用重写.htacess但它给了我一个错误(500内部服务器错误),这是我的原始php网址

http://www.example.com/viewtopic.php?topic=lovetopic

我想将其更改为:

http://www.example.com/lovetopic

这是我的整个htaccess代码是这样的:

RewriteEngine On
RewriteRule ^user/([^/]*)$ /viewprofile.php?user=$1 [L]
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

我不知道问题是什么

编辑服务器错误日志给我这个错误

[Thu Oct 14 20:34:36 2010] [error] 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., 

1 个答案:

答案 0 :(得分:4)

您的第二条规则^([^/]*)$的模式也匹配/viewtopic.php而没有路径前缀/,即viewtopic.php。这就是你有无限递归的原因。

您可以使用以下条件排除:

RewriteCond $1 !=viewtopic.php
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

或使用此条件排除所有现有文件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

或者在您面前使用此规则,以阻止可以映射到由以下任何规则重写的现有文件的每个请求:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
相关问题