You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

遭遇500 Internal Server Error,Apache日志报RewriteEngine命令无效错误求解决

解决Apache中"Invalid command 'RewriteEngine'"错误的方案

错误原因

出现这个500错误,核心原因是Apache未启用mod_rewrite模块,导致无法识别RewriteEngine指令。

解决方案

1. 启用mod_rewrite模块

  • Debian/Ubuntu 系列系统
    执行以下命令启用模块:

    sudo a2enmod rewrite
    

    然后重启Apache服务:

    sudo systemctl restart apache2
    
  • CentOS/RHEL 系列系统
    编辑Apache主配置文件(通常路径为/etc/httpd/conf/httpd.conf),找到如下行:

    #LoadModule rewrite_module modules/mod_rewrite.so
    

    删除行首的注释符号#,保存文件后重启Apache:

    sudo systemctl restart httpd
    
  • Windows 系统
    打开Apache配置文件httpd.conf,找到以下行:

    #LoadModule rewrite_module modules/mod_rewrite.so
    

    删除行首的#,保存后重启Apache服务。

2. 确保目录允许重写规则生效

启用模块后,需确认网站根目录(或目标目录)的Apache配置允许.htaccess文件的重写规则生效。找到对应目录的<Directory>配置块,将AllowOverride参数修改为All:

<Directory "/var/www/html">
    AllowOverride All
</Directory>

修改完成后重启Apache服务。

3. 检查指令拼写

最后确认.htaccess或配置文件中的RewriteEngine拼写正确,避免出现拼写错误(比如少写字母、错写大小写)。

内容的提问来源于stack exchange,提问作者K_G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 18:38:09