要在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
文件中的重寫規則了。