在向.htaccess添加重写后,我的表单无效。我发现很多主题都有类似的问题,但都没有解决我的问题。 如果你能看看,我将不胜感激。 那是:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
这是我的邮政编码:)
<?php
function send_email ($to_email, $from_email, $from_name, $subject, $msg,
$showinfo) {
//split up to email array, if given
if (is_array($to_email)) {
$to_email_string = implode(', ', $to_email);
}
else {
$to_email_string = $to_email;
}
// build content
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;"
cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Imie i nazwisko:
</strong> </td><td>" . strip_tags( $from_name ) . "</td></tr>";
$message .= "<tr><td><strong>E-mail:</strong> </td><td>" . strip_tags(
$from_email ) . "</td></tr>";
$message .= "<tr><td><strong>Temat:</strong> </td><td>" . strip_tags(
$subject ) . "</td></tr>";
$message .= "<tr><td><strong>Wiadomość:</strong> </td><td>" . nl2br(
strip_tags( $msg ) ) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
//Assemble headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from_name <$from_email>" . "\r\n";
//send via PHP's mail() function
if( $showinfo )
{
mail($to_email_string, $subject, $message, $headers) or die(json_encode(
array( 'error' => true, 'msg' => 'Fel när du skickar meddelanden.')));
echo json_encode( array( 'error' => false, 'msg' => "Ditt meddelande har
skickats."));
} else {
mail($to_email_string, $subject, $message, $headers);
}
}
if( isset( $_POST['name']) && isset( $_POST['email']) && isset(
$_POST['subject']) && isset( $_POST['message']) && $_POST['other'] == '')
{
send_email( "myemail", $_POST['email'], $_POST['name'],
$_POST['subject'], $_POST['message'], true );
send_email( $_POST['email'], 'myemail', "LHI", 'Copy: ' .
$_POST['subject'], $_POST['message'], false );
}
if( isset( $_POST['info']) && $_POST['info'] == 'notajax' )
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://localhost/dash/");
}
感谢您的帮助。
答案 0 :(得分:0)
也许您需要删除
中的.phpRewriteCond %{REQUEST_FILENAME}.php -f
加载页面时是否有任何错误消息?
答案 1 :(得分:0)
将此添加到您的所有重写条件之上。
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]
所以你的.htaccess将是:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
希望这有帮助!