Jim Baker
Jim Baker

Reputation:

form post to mod_rewrite url

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:

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

I have a .htaccess file inside my login directory:

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...

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

GET http://localhost/login/ 200 OK

Any tips would be great.

Thanks

Upvotes: 0

Views: 5694

Answers (2)

Erik Čerpnjak
Erik Čerpnjak

Reputation: 11

I have a condition in my .htaccess file:

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

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

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.

Putting the www in the form like this:

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

instead of:

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

fixed the problem for me.

Upvotes: 1

Artem Russakovskii
Artem Russakovskii

Reputation: 22023

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.

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

[QSA,L]

Upvotes: 0

Related Questions