So I have this in my .htaccess file, trying to rid myself of the .php following each URL on my site. And it works, just as intended, it takes the .php out, just like a charm. However, this rewrite condition is breaking my login functionality. Once inside the login wall, there is not a problem, I can scoot around to any one of the files, but for some reason, I can not login with this Condition in place. As soon as I delete it, users can login.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
In case you want my php file for the login page (index.php)
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
// it will never let you open index(login) page if session is set
if ( isset($_SESSION['User'])!="" ) {
header("Location: home.php");
exit;
}
$error = false;
if( isset($_POST['btn-login']) ) {
// old source code with no relevance
$email = trim($_POST['email']);
$email = strip_tags($email);
$email = htmlspecialchars($email);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
if(empty($email)){
$error = true;
$emailError = "Please enter your email address.";
} else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$error = true;
$emailError = "Please enter valid email address.";
}
if(empty($pass)){
$error = true;
$passError = "Please enter your password.";
}
// if there's no error, continue to login
if (!$error) {
$conn = new mysqli($servername, $username, $dbpassword, $dbname);
$password = hash('sha256', $pass); // password hashing using SHA256 do not use, it's not secure
$sql = "SELECT UserID, FirstName, Password FROM Users WHERE Email='$email'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$count = $result->num_rows;
if( $count == 1 && $row['Password']==$password ) {
$_SESSION['User'] = $row['UserID'];
header("Location: home.php");
} else {
$errMSG = "Incorrect Credentials, Try again...";
}
}
}
?>
Thanks guys