在 Debian 上开启 Apache 的 rewrite(重写) 功能,一般按下面几步来:
Apache 的 rewrite 功能由 mod_rewrite 提供。
sudo a2enmod rewrite
执行后会提示你重启 Apache。
sudo systemctl restart apache2
Debian 默认的 Apache 配置中,AllowOverride 通常是 None,会导致 .htaccess 不生效。
编辑你的站点配置,例如:
sudo nano /etc/apache2/sites-available/000-default.conf
在 <VirtualHost> 里加上:
<Directory /var/www/html>
AllowOverride All
</Directory>
如果你用的是其他目录,改成对应路径。
sudo systemctl restart apache2
在网站根目录创建 .htaccess:
RewriteEngine On
RewriteRule ^test$ index.php [L]
访问:
http://你的IP/test
如果能正常访问 index.php,说明 rewrite 已开启。
.htaccess 不生效 → 检查 AllowOverride All.htaccess 语法.htaccess如果你用的是 Debian + PHP + Laravel / WordPress,我也可以给你具体配置示例。