在 Linux 系统中,.htaccess
文件是 Apache Web 服务器用来配置目录级设置的重要文件。以下是关于它的关键信息:
.htaccess
文件通常位于 网站根目录 或其子目录中:
bash
/var/www/html/.htaccess # 默认网站根目录
/var/www/your_site/public_html/.htaccess # 虚拟主机或用户目录
sudo find /var/www -type f -name ".htaccess"
(替换 /var/www
为你的网站实际路径)
检查 Apache 的虚拟主机配置(通常在 /etc/apache2/sites-available/
):
grep "DocumentRoot" /etc/apache2/sites-available/*.conf
输出的 DocumentRoot
路径即为 .htaccess
可能存在的目录。
.htaccess
以点开头,默认隐藏。用 ls -a
查看。www-data
)有读取权限:
bash
sudo chmod 644 /path/to/.htaccess
sudo chown www-data:www-data /path/to/.htaccess
AllowOverride
已启用(通常在 <Directory>
段中)。bash
sudo touch /var/www/html/.htaccess
sudo nano /var/www/html/.htaccess
apache
RewriteEngine On
RewriteRule ^old-page$ new-page [R=301,L]
.htaccess
,需将规则转换到 Nginx 配置中。.htaccess
,但路径可能不同。如果需要进一步帮助(如调试规则或权限问题),请提供更多上下文!