.htaccess文件扩展名删除器代码破坏了网站表格

阿巴斯

因此,我在HTACCESS中拥有了这段代码,这很棒,因为如果访问者进入带有.php文件扩展名的页面,它将首先从页面中删除.php文件扩展名,然后允许该页面加载而无需扩展名。(因此,它只是修饰URL)

# 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.Cyber​​BytesInc.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代码正常工作,除了从/ resources / scripts /文件夹访问文件时,我不知道解决此问题的最佳方法。

您现在可以转到该站点,以查看它因此无法正常工作。目前,我可能要删除上述代码行,因此我的表单至少可以正常工作。因此,如果您查看该站点并且该表单正在运行,那是因为我删除了上面的.htaccess,直到我弄清楚如何在其中成功放置它。

谢谢!

编辑:question-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.');

}
阿努巴瓦

更改规则以跳过POST请求:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

删除.HTACCESS文件中的所有扩展名

来自分类Dev

删除文件扩展名htaccess不起作用

来自分类Dev

使用.htaccess文件扩展名删除程序代码时,网站表单不包含任何值

来自分类Dev

.htaccess删除文件扩展名不起作用

来自分类Dev

htaccess重写规则并删除php文件扩展名

来自分类Dev

htaccess重写并删除.php扩展名

来自分类Dev

htaccess在多个系统文件扩展名上删除.php

来自分类Dev

.htaccess破坏了我的网站

来自分类Dev

删除.htaccess中的扩展名时无法访问子文件夹中的文件

来自分类Dev

htaccess删除了文件扩展名,但扩展名仍然存在

来自分类Dev

.htaccess删除单个文件的扩展名

来自分类Dev

使用htaccess文件删除html扩展名

来自分类Dev

使用.htaccess删除文件上的重复扩展名

来自分类Dev

.htaccess如何删除文件扩展名和索引文件

来自分类Dev

htaccess添加文件扩展名或绕过

来自分类Dev

删除文件扩展名htaccess不起作用

来自分类Dev

删除文件夹名称HTACCESS和文件扩展名?

来自分类Dev

用htaccess删除.php扩展名

来自分类Dev

使用.htaccess删除多个文件扩展名

来自分类Dev

如何使用Htaccess删除多个文件扩展名并重定向文件扩展名URL

来自分类Dev

htaccess不会删除php扩展名

来自分类Dev

htaccess删除了文件扩展名,但扩展名仍然存在

来自分类Dev

.htaccess删除单个文件的扩展名

来自分类Dev

当用户使用htaccess直接在网址中键入扩展名时,从文件中删除扩展名

来自分类Dev

.htaccess:文件和文件扩展名

来自分类Dev

如何删除单个文件的.php文件扩展名?(.htaccess)

来自分类Dev

消除多个文件扩展名.htaccess

来自分类Dev

需要 .htaccess 中的文件扩展名

来自分类Dev

HTACCESS 破坏了 PHP 代码和 Xampp 服务器

Related 相关文章

  1. 1

    删除.HTACCESS文件中的所有扩展名

  2. 2

    删除文件扩展名htaccess不起作用

  3. 3

    使用.htaccess文件扩展名删除程序代码时,网站表单不包含任何值

  4. 4

    .htaccess删除文件扩展名不起作用

  5. 5

    htaccess重写规则并删除php文件扩展名

  6. 6

    htaccess重写并删除.php扩展名

  7. 7

    htaccess在多个系统文件扩展名上删除.php

  8. 8

    .htaccess破坏了我的网站

  9. 9

    删除.htaccess中的扩展名时无法访问子文件夹中的文件

  10. 10

    htaccess删除了文件扩展名,但扩展名仍然存在

  11. 11

    .htaccess删除单个文件的扩展名

  12. 12

    使用htaccess文件删除html扩展名

  13. 13

    使用.htaccess删除文件上的重复扩展名

  14. 14

    .htaccess如何删除文件扩展名和索引文件

  15. 15

    htaccess添加文件扩展名或绕过

  16. 16

    删除文件扩展名htaccess不起作用

  17. 17

    删除文件夹名称HTACCESS和文件扩展名?

  18. 18

    用htaccess删除.php扩展名

  19. 19

    使用.htaccess删除多个文件扩展名

  20. 20

    如何使用Htaccess删除多个文件扩展名并重定向文件扩展名URL

  21. 21

    htaccess不会删除php扩展名

  22. 22

    htaccess删除了文件扩展名,但扩展名仍然存在

  23. 23

    .htaccess删除单个文件的扩展名

  24. 24

    当用户使用htaccess直接在网址中键入扩展名时,从文件中删除扩展名

  25. 25

    .htaccess:文件和文件扩展名

  26. 26

    如何删除单个文件的.php文件扩展名?(.htaccess)

  27. 27

    消除多个文件扩展名.htaccess

  28. 28

    需要 .htaccess 中的文件扩展名

  29. 29

    HTACCESS 破坏了 PHP 代码和 Xampp 服务器

热门标签

归档