Reputation: 17
I have a problem with a _POST variables which is empty after URL rewriting and redirection.
HTML:
<article class="span6">
<textarea id="msg" rows="3" cols="40" name="message" placeholder="Message">Détails</textarea>
</article>
<article class="span6">
<input type="text" name="adresse" id="adresse">
<input size="100" type="text" name="name" id="name" placeholder="Nom">
<input type="text" size="30" id="email" name="email" placeholder="Adresse e-mail">
<button type="submit" name="submit" id="submit" class="btn btn-renova-alt add-top-half">Send message</button>
</article>
</form>
PHP :
<?php
if($adresse != "" ){
}
else{
if(isset($_POST['submit']))
{
$to = "[email protected]";
$subject = "Email from";
$name_field = stripslashes($_POST['name']);
$email_field = $_POST['email'];
$message = stripslashes($_POST['message']);
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body .= "From: $name_field <br/> E-Mail: $email_field <br/> Message: <br/> $message";
$body .= "</body>\n";
$body .= "</html>\n";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\n";
$headers .= 'Reply-to: '.$name_field. '<'.$email_field.'>' . "\n" ;
$headers .= 'Return-path: '.$name_field. '<'.$email_field.'>' . "\n" ;
$headers .= 'From: MGS < [email protected] >' . "\r\n";
$name_field = stripslashes($name_field);
$message = stripslashes($message);
mail($to, $subject, $body, $headers);
unset($name_field);
unset($email_field);
unset($message);
}
else
{
echo "Failure!";
}
}
?>
htaccess :
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.example\.com$
#RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
The URL is rewritten correctly but I get an empty value for my POST variable. PS: I don't get none past variables by the form
Do you have a solution to this? thank you
Upvotes: 2
Views: 2301
Reputation: 143966
Either don't redirect when you're submitting POST requests:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Or ensure that the form's action is the entire full URL:
<form method=POST action="https://www.example.com/submit-whatever">
Upvotes: 1
Reputation: 91792
This is the problem:
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
You should change that to:
RewriteRule ^(.*)$ /$1 [R,L]
You are redirecting to a different url (although it is probably the same url, it's stil a redirect), causing POST
information to get lost.
Upvotes: 0