2013-12-20 51 views
1

所以我在我的HTACCESS這個代碼非常好,因爲它首先從我的頁面中刪除.php文件擴展名,如果訪問者進入帶有.php文件擴展名的頁面,然後它允許頁面在沒有擴展名的情況下加載。 (所以它只是prettying了URL).htaccess文件擴展名卸妝代碼打破網站表格

# REMOVE FILE EXTENSIONS 
RewriteEngine On 

# browser requests PHP 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] 

# check to see if the request is for a PHP file 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^/?(.*)$ /$1.php [L] 

它的偉大工程,但後來我碰到網頁上的問題:http://www.CyberBytesInc.com/contact因爲我有召喚出一個PHP文件發送形式:

<form id="request-form" action="resources/script/question-send.php" method="post"> 

而上面的htaccess代碼刪除了這個文件的.php文件,我得到了錯誤代碼「不允許直接訪問這個頁面」。這是腳本里面,它是

} else { 
    die('Direct access to this page is not allowed.'); 
} 

有一次,我從htaccess的雖然然後它開始工作刪除此:

# browser requests PHP 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] 

但我不明白的是振作刪除文件擴展名如果.php被放置在頁面的末尾(Google的很多索引與文件擴展名,我試圖刪除此。

我想如果我能以某種方式使它,所以htaccess的代碼工作,除了當從my/resources/scripts /文件夾訪問文件時,我不知道最好解決這個問題的方法。

您可以立即前往該網站查看是否因此而無法正常工作。暫時我可能會刪除上面提到的代碼行,所以我的表單至少工作。因此,如果您查看網站並且表單正在工作,那是因爲我刪除了上述.htaccess,直到我找出如何成功將其放入該網站。

謝謝!

編輯:對於問題 - send.php

<?php 

// Get email address 
$email_address = '[email protected]'; 

// Ensures no one loads page and does simple spam check 
if(isset($_POST['name']) && empty($_POST['spam-check'])) { 

    // Declare our $errors variable we will be using later to store any errors 
    $error = ''; 

    // Setup our basic variables 
    $input_name = strip_tags($_POST['name']); //required 
    $input_email = strip_tags($_POST['email']); //required 
    $input_subject = strip_tags($_POST['subject']); 
    $input_message = strip_tags($_POST['message']); //required 

    // We'll check and see if any of the required fields are empty 
    if(strlen($input_name) < 2) $error['name'] = '<label for="question-name">Please enter your <b>Name</b></label>'; 
    if(strlen($input_message) < 5) $error['message'] = '<label for="question-message">Please leave a longer <b>Message</b></label>'; 

    // Make sure the email is valid 
    if(!filter_var($input_email, FILTER_VALIDATE_EMAIL)) $error['email'] = '<label for="question-email">Please enter a valid <b>Email Address</b></label>'; 

    // Set a subject & check if custom subject exist 
    if($input_subject) $subject = "(Question) - $input_subject"; 
    else $subject = "(Question) - No Subject"; 
    // $message .= "$input_message\n"; 
    $message .= "\n\n---\nThis email was sent by $input_name from $input_email"; 

    // Now check to see if there are any errors 
    if(!$error) { 

     // No errors, send mail using conditional to ensure it was sent 
     if(mail($email_address, $subject, $message, "From: $input_email")) { 
      echo '<p class="success"><b>EMAIL SENT SUCCESSFULLY.</b><br />' . "Dear $input_name, " . 'thank you for contacting CyberBytes Inc. Please allow us <b>24-48</b> hours to review your request and get back to you. If you need a response sooner, please contact us via telephone at (716) 876-1824.<br /><br /><b>Please verify that this is your correct Email Address:</b><br />' . "Email Address: <i>$input_email</i>" . '<br /><br /><span class="red"><b>PLEASE NOTE:</b></span><br /> If we do not respond to your request within a reasonable amount of time, please give us a call as there may have been an error on our end with your request.</p>'; 
     } else { 
      echo '<p class="error">There was a problem sending your email! Please give us a call at (716) 876-1824 as there seems to be an error on our end with the form.</p>'; 
     } 

    } else { 

     // Errors were found, output all errors to the user 
     $response = (isset($error['name'])) ? $error['name'] . "\n" : null; 
     $response .= (isset($error['email'])) ? $error['email'] . "\n" : null; 
     $response .= (isset($error['message'])) ? $error['message'] . "\n" : null; 

     echo "<p class='error'>$response</p>"; 

    } 

} else { 

    die('Direct access to this page is not allowed.'); 

} 
+0

這部分的全部代碼...否則{ 模具(「直接不允許訪問此頁面。'); } – Hackerman

+0

剛纔在上面加了,謝謝! – abass

+1

如果你改變這個動作=「resources/script/question-send.php」..to this:action =「resources/script/question-send」 – Hackerman

回答

2

更改您的規則的完整代碼跳過POST要求:

# browser requests PHP 
RewriteCond %{REQUEST_METHOD} !POST 
RewriteCond %{THE_REQUEST} ^\s/([^\ ]+)\.php 
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] 
+0

謝謝你,我會在將來嘗試。我設法弄清楚問題在哪裏。儘管這絕對是一個很好的解決方案! – abass

+0

很高興你的問題得到解決,你喜歡我的答案 – anubhava