HTML POST重定向问题

HTML POST Redirection issue

本文关键字:问题 重定向 POST HTML      更新时间:2023-09-26

我正在尝试为我的网站创建一个新的登录页面,我使用nodejs来创建登录部分。所以我使用html-post方法来传递参数。。所以基本上我有一个登录部分,注册部分和忘记密码部分。我把每个表单动作分别给了路径/本地、/注册和/忘记。。我只有一页的主题。因此只有一个索引文件可以处理所有这些特性。所以当我提交这些表格时。。。如果不合格,它将转到urlhttp://www.mycustomurl/local或http://www.mycustomurl/signup或http://www.mycustomurl/local/forgot并被重定向到这些页面。。我已经创建了index.html页面的副本,文件名为signup.html、local.html和forget.html。是否可以将表单提交重定向到当前页面本身??哪种方法最好?

如果我正确理解了你的问题,你应该可以用expressJS来解决。您可以设置不同的路由来提供相同的文件。这样的东西应该行得通。

app.post('local', function(request, response){
    //your code that does stuff here
    //if successful 
        //do your action
    //if unsuccessful
        //serve your single page
        response.sendfile(path_to_file_index);
});
app.post('signup', function(request, response){
    //your code that does stuff here
    //if successful 
        //do your action
    //if unsuccessful
        //serve your single page
        response.sendfile(path_to_file_index);
});
app.post('forgot', function(request, response){
    //your code that does stuff here
    //if successful 
        //do your action
    //if unsuccessful
        //serve your single page
        response.sendfile(path_to_file_index);
});

可以通过.htaccess文件进行重定向:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.abc.com$ [NC]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]

RewriteEngine On
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]