要在Apache2中启用重写模块,请按照以下步骤操作:
打开终端(在Linux系统中)。
输入以下命令以启用mod_rewrite
模块:
sudo a2enmod rewrite
mod_headers
模块(在某些情况下可能需要),请运行以下命令:sudo a2enmod headers
sudo systemctl restart apache2
或者
sudo service apache2 restart
或者
sudo /etc/init.d/apache2 restart
/etc/apache2/sites-available/
目录下)中的AllowOverride
指令设置为All
。这将允许.htaccess
文件中的重写规则生效。例如:<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
现在,您已经在Apache2中启用了重写模块,可以开始使用.htaccess
文件中的重写规则了。