要启用 'mod_rewrite' 重写模块,需要按照以下步骤操作:

  1. 确认 Apache 服务器已经安装 'mod_rewrite' 模块。可以使用以下命令检查:
apahe2ctl -M | grep rewrite

如果输出中包含 'rewrite_module',表示 'mod_rewrite' 已经安装。

  1. 启用 'mod_rewrite' 模块。可以使用以下命令:
a2enmod rewrite
  1. 修改 Apache 配置文件,开启 'mod_rewrite' 重写规则。在 VirtualHost 或 Directory 中添加以下配置:
<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

这里的 /var/www/html 是网站的根目录。'AllowOverride' 指令开启了 '.htaccess' 文件的使用,允许在 '.htaccess' 中定义 'mod_rewrite' 规则。

  1. 重启 Apache 服务器,使配置生效:
systemctl restart apache2

现在,'mod_rewrite' 重写模块已经启用并开启了重写规则。可以通过编辑 '.htaccess' 文件来定义自己的重写规则。

如何启用 Apache mod_rewrite 重写模块

原文地址: https://www.cveoy.top/t/topic/mO29 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录