Reputation: 409
There's a secure page in public_html profile.php which checks whether the user is logged in. It redirects to login.php when not logged in. It works when I try to access http://my-domain.com/profile but not when http://my-domain.com/profile/ (slash at the end)
here my .htaccess
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</ifModule>
index.php
<?php
$path = $_SERVER['REQUEST_URI'];
$chunks = explode("/", $path);
//print_r($chunks);
if($chunks[1] == "profile") {
if($chunks[2] != "") {
$profile_id = $chunks[2];
require_once("profile.php");
} else {
require_once("profile.php");
}
}
?>
profile.php
<?php
require_once("../includes/initialize.php");
if(!$session->is_logged_in()) {
redirect_to("login.php");
}
if(isset($_GET['id'])) {
$profile_id = $_GET['id'];
}
echo "This is the profile page of ID: ".$profile_id;
?>
Upvotes: 0
Views: 41
Reputation: 16103
Thats because with the trailing slash it is a directory and it matches the -d
test.
I use this bit to make sure I never have a trailing slash
## Redirect to remove trailing slashes on extensionless URL requests
# If requested URL ending with slash does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Externally redirect to remove trailing slash
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
Upvotes: 1