url重写内部服务器错误

时间:2013-08-04 02:43:15

标签: apache mod-rewrite

每次在我的.htaccess文件中实现此代码进行模式重写时,我都会遇到错误

RewriteEngine On 
RewriteRule   ^commenting/([0-9]+)/?$commenting.php?id=$1

我正在尝试转换

domain/commenting.php?id=15

这样的东西
domain/commenting/15

代码或托管是否有问题。我还没有下载任何需要的插件吗? 任何帮助将不胜感激, 感谢

错误是这样的:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete        your request.

Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

1 个答案:

答案 0 :(得分:1)

你在规则的左手和右手之间缺少一个空格。

RewriteRule ^commenting/([0-9]+)/?$ /commenting.php?id=$1

您可能还需要启用RewriteEngineOptions以下内容:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteRule ^commenting/([0-9]+)/?$ /commenting.php?id=$1

如果您在此之后仍然获得500,请尝试将上述规则放在这些标记<IfModule mod_rewrite.c>...</IfModule>之间,如下所示:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews

    RewriteEngine On
    RewriteRule ^commenting/([0-9]+)/?$ /commenting.php?id=$1
</IfModule>

以上基本上意味着只有在使其工作的模块可用时才执行规则。