htaccess&变量_POST

时间:2013-11-20 20:31:19

标签: php html5 .htaccess

我有一个_POST变量的问题,在URL重写和重定向后它是空的。

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 = "daniel@example.com";
$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 < contact@example.com >' . "\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]

URL被正确重写但我的POST变量得到一个空值。 PS:我没有通过表格

获得任何过去的变量

你有解决方案吗? 谢谢

2 个答案:

答案 0 :(得分:1)

当您提交POST请求时,要么不重定向:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

或确保表单的操作是完整的完整网址:

<form method=POST action="https://www.example.com/submit-whatever">

答案 1 :(得分:0)

这是问题所在:

RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

您应该将其更改为:

RewriteRule ^(.*)$ /$1 [R,L]

您正在重定向到其他网址(尽管它可能是相同的网址,但它仍然是重定向),导致POST信息丢失。