使用 index.html 时,由于 .htaccess 配置错误,JQuery ajax 抛出 403 forbidden 错误

时间:2021-08-01 18:34:35

标签: ajax .htaccess

Xampp Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11

我使用 Hugo 静态生成器创建了一个简单的博客。该站点发布在“public”文件夹中,并且已经创建了一个主机 (blog.test)。在底部,我有一个简单的时事通讯注册表。我正在使用 JQuery ajax 将数据发布到“subscribe.php”,它位于根文件夹中。

$.ajax({
        method: "POST",
        url: "/subscribe.php",
        data: {"email" : $("#email").val()},
        dataType: 'json',
        contentType: 'application/json',
        ...

最初 ajax 调用根本不起作用。快速搜索将我指向 .htaccess。我没有 index.php 而是 index.html 因为它是一个静态站点。这是我对 .htaccess 文件的第一次尝试:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} subscribe.php
RewriteRule .* - [F,L]
</IfModule>

现在出现错误403 forbidden。我在 .htaccess 中做了一些其他更改,但仍然出现相同的错误。任何问题的指针?

干杯

0 个答案:

没有答案