更改我的 .htaccess 文件后,我的 php 上的 POST 方法不再起作用

Gui*_*rum 2 php .htaccess

我最近做了一些研究,了解如何修改 .htaccess 文件以隐藏 URL 中的 .php 扩展名。我使用以下代码让它按照我想要的方式工作:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.guitrum.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.guitrum.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

ErrorDocument 404 /404.php

DirectoryIndex index.php
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的 php 脚本的一部分现在被破坏了。请记住,在修改我的 .htaccess 文件之前,一切正常。在登录页面上,我有一些脚本可以使用 POST 方法传递一些用户输入,如下所示:

<form method='POST' action='loginconfirm.php'>
Password: <input type='password' name='password'></input>
<input type='submit' name='submit' value='Go'></input>
</form>
Run Code Online (Sandbox Code Playgroud)

在 loginconfirm.php 页面上,我有一个加密类作为页面中的包含文件,代码如下:

<?php
//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
class Encryption {

    const CYPHER = MCRYPT_RIJNDAEL_256;
    const MODE = MCRYPT_MODE_CBC;
    const KEY = 'SecretKey';

    public function encrypt($plaintext) {
        $td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, self::KEY, $iv);
        $crypttext = mcrypt_generic($td, $plaintext);
        mcrypt_generic_deinit($td);
        return rawurlencode(base64_encode($iv . $crypttext));
    }

    public function decrypt($crypttext) {
        $crypttext = rawurldecode($crypttext);
        $crypttext = base64_decode($crypttext);
        $plaintext = '';
        $td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
        $ivsize = mcrypt_enc_get_iv_size($td);
        $iv = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, self::KEY, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }
        return trim($plaintext);
    }

}

//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
?>
Run Code Online (Sandbox Code Playgroud)

我在页面上做的第一件事是设置一个新变量,该变量对密码进行了加密,如下所示:

<?php
include ("includefiles/EncryptionUtilities.php");
$passworde = Encryption::encrypt($_POST['password']);
setcookie('password', $passworde, time() + (60 * 5));
?>
Run Code Online (Sandbox Code Playgroud)

正常情况下它可以正常工作,现在它会抛出错误:

空字符串被传递到 EncryptionUtilities.php 中,并且无法修改标头信息 - 标头已发送。

我认为 .htaccess 文件有问题,不允许 POST 方法在页面之间进行通信。

anu*_*ava 5

对于外部重定向,POST 数据不会重定向并且会丢失。将您的.php规则替换为:

# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /.+?\.php [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]
Run Code Online (Sandbox Code Playgroud)