将帖子发布到mod_rewrite网址

时间:2022-04-02 11:22:13

I am trying to submit a form to the url "localhost/login". Inside my login directory I have an index.php file with the code I am using to debug that the post is working:

我正在尝试将表单提交到URL“localhost / login”。在我的登录目录中,我有一个index.php文件,其中包含我用来调试帖子工作的代码:

<?php
echo $_POST['username'];
?>

I have a .htaccess file inside my login directory:

我的登录目录中有一个.htaccess文件:

RewriteEngine on
RewriteRule ^. index.php [L]

The problem is, when I post to localhost/login my firebug shows that the initial POST goes through, but then redirects to login.php as a GET request without any POST variables...

问题是,当我发布到localhost / login时,我的firebug显示初始POST通过,但随后重定向到login.php作为GET请求,没有任何POST变量...

POST http://localhost/login?password=test_password&remember=true&username=test_username 301 Moved Permanently

POST http:// localhost / login?password = test_password&remember = true&username = test_username 301永久移动

GET http://localhost/login/ 200 OK

GET http:// localhost / login / 200好的

Any tips would be great.

任何提示都会很棒。

Thanks

2 个解决方案

#1


I have a condition in my .htaccess file:

我的.htaccess文件中有一个条件:

RewriteBase /
RewriteCond %{HTTP_HOST} !^www(.*)
RewriteRule ^(.*) http://www.%{HTTP_HOST}%{REQUEST_URI}

which rewrites any links without the prefix "www". Like this:

它会重写没有前缀“www”的任何链接。像这样:

http://mysite.com to http://**www**.mysite.com

And that was the problem I had:

这就是我遇到的问题:

in my form I have forgotten to put the "www" and so my POST array was empty.

在我的形式我忘了把“www”,所以我的POST阵列是空的。

Putting the www in the form like this:

把www放在这样的表格中:

action="http://www.mysite.com/login"

instead of:

action="http://mysite.com/login"

fixed the problem for me.

为我解决了这个问题。

#2


Based on my research, POST should be allowed to be rewritten and come out as POST, any sort of problem is probably due to something else going wrong, like your code.

根据我的研究,POST应该被允许重写并作为POST出现,任何类型的问题都可能是由于其他问题,比如你的代码。

Btw, in general, to keep the GET parameters from being stripped, use the QSA directive:

通常,为了防止GET参数被剥离,请使用QSA指令:

[QSA,L]

#1


I have a condition in my .htaccess file:

我的.htaccess文件中有一个条件:

RewriteBase /
RewriteCond %{HTTP_HOST} !^www(.*)
RewriteRule ^(.*) http://www.%{HTTP_HOST}%{REQUEST_URI}

which rewrites any links without the prefix "www". Like this:

它会重写没有前缀“www”的任何链接。像这样:

http://mysite.com to http://**www**.mysite.com

And that was the problem I had:

这就是我遇到的问题:

in my form I have forgotten to put the "www" and so my POST array was empty.

在我的形式我忘了把“www”,所以我的POST阵列是空的。

Putting the www in the form like this:

把www放在这样的表格中:

action="http://www.mysite.com/login"

instead of:

action="http://mysite.com/login"

fixed the problem for me.

为我解决了这个问题。

#2


Based on my research, POST should be allowed to be rewritten and come out as POST, any sort of problem is probably due to something else going wrong, like your code.

根据我的研究,POST应该被允许重写并作为POST出现,任何类型的问题都可能是由于其他问题,比如你的代码。

Btw, in general, to keep the GET parameters from being stripped, use the QSA directive:

通常,为了防止GET参数被剥离,请使用QSA指令:

[QSA,L]