I recently did some research to find out how to modify my .htaccess file to hide the .php extension in the URL. I got it to work how I wanted with the following code:
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
Unfortunately, part of my php script is broken now. Keep in mind, before modifying my .htaccess file, everything worked. On a log in page, I have some script to pass some user input with the POST method like so:
<form method='POST' action='loginconfirm.php'>
Password: <input type='password' name='password'></input>
<input type='submit' name='submit' value='Go'></input>
</form>
on the loginconfirm.php page, I have an encryption class as an included file in the page with the following code:
<?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
?>
The first thing I do on the page is set a new variable that has the password encrypted like so:
<?php
include ("includefiles/EncryptionUtilities.php");
$passworde = Encryption::encrypt($_POST['password']);
setcookie('password', $passworde, time() + (60 * 5));
?>
When normally it would work fine, now it throws errors saying that:
an empty string was passed into EncryptionUtilities.php, and cannot modify header information - headers already sent.
I think there is something wrong with the .htaccess file that is not allowing the POST method to talk between pages.