.htaccess 在服务器上产生 404,但通过了 htaccess 验证器
.htaccess produces 404 on server, but passes htaccess validators
我很困惑为什么这不起作用。当我使用在线 .htaccess
验证器时,一切都很好。它按预期工作。但是,生产服务器上的相同 .htaccess
会收到 404 响应。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api/index.php?_REQUEST= [NC,L]
在000-default.conf
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
对于某些上下文。该站点使用子域。它是 运行 在具有 Ubuntu 20.04.2 LTS、Apache2 2.4.41 和 PHP 7.4.3
的 AWS EC2 实例上
这个完全相同的配置在另一个实例上工作得很好,唯一的区别是子域。期望的结果:
subdomain.example/api/data/data
重写为 subdomain.example/api/index.php?Querystring
将 data/data 作为查询字符串发送。虽然我不是 .htaccess
专家,远非专家,但我很困惑为什么这不起作用并产生 404。
分辨率:
确保您没有在尝试重写的实际目录中留下相同的 .htaccess 文件。在这种情况下,api/。删除错误的 .htaccess 文件并重新启动 apache 解决了这个问题。
我很困惑为什么这不起作用。当我使用在线 .htaccess
验证器时,一切都很好。它按预期工作。但是,生产服务器上的相同 .htaccess
会收到 404 响应。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api/index.php?_REQUEST= [NC,L]
在000-default.conf
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
对于某些上下文。该站点使用子域。它是 运行 在具有 Ubuntu 20.04.2 LTS、Apache2 2.4.41 和 PHP 7.4.3
的 AWS EC2 实例上这个完全相同的配置在另一个实例上工作得很好,唯一的区别是子域。期望的结果:
subdomain.example/api/data/data
重写为 subdomain.example/api/index.php?Querystring
将 data/data 作为查询字符串发送。虽然我不是 .htaccess
专家,远非专家,但我很困惑为什么这不起作用并产生 404。
分辨率: 确保您没有在尝试重写的实际目录中留下相同的 .htaccess 文件。在这种情况下,api/。删除错误的 .htaccess 文件并重新启动 apache 解决了这个问题。