在 Debian 上让 Apache 支持 URL Rewrite(重写),通常步骤如下:
sudo a2enmod rewrite
启用后重启 Apache:
sudo systemctl restart apache2
编辑你的站点配置,例如:
sudo nano /etc/apache2/sites-available/000-default.conf
在 <VirtualHost *:80> 里加上:
<Directory /var/www/html>
AllowOverride All
</Directory>
⚠️ 默认是
AllowOverride None,不改成All,.htaccess不会生效
保存后重启 Apache:
sudo systemctl restart apache2
.htaccess在网站根目录(如 /var/www/html)创建或编辑 .htaccess:
RewriteEngine On
RewriteRule ^test$ index.php [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
apache2ctl -M | grep rewrite
应看到:
rewrite_module (shared)
sudo tail -f /var/log/apache2/error.log
如果你告诉我:
我可以给你更精确的配置。