首页 文章

.htaccess url为POST请求重写

提问于
浏览
-3
$.ajax({
    type: "POST",
    url: 'data.php',
    data: {
        cc: cc,
        mobile: mobile,
        captcha: captcha
    },
    success: function (data) {
        console.log(data);
    }
});

我想使用url: /signup ,而不是 data.php . 如何使用 .htaccess 重写实现它 . 请帮助我在我的 .htacceess 文件 RewriteRule ^signup/?$ /data.php [L] 中尝试了这个但是它抛出错误 404 .

1 回答

  • 2

    以下 RewriteRule 应该有效 .

    RewriteEngine On
    RewriteRule signup data.php
    

    如果您未启用覆盖,则必须更改它

    / etc / apache2 / sites-enabled / 000-default

    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    

    AllowOverride 无更改为 AllowOverride All

    并且AJAX URL可以

    $.ajax({
           type: "POST",
           url: '/signup',
           data: {cc: cc, mobile: mobile, captcha: captcha
        },
        success: function (data) {
           console.log(data);
        }
    });
    

相关问题