In the root I have files: .htaccess
and page.php
In the /test/
subfolder I have files: define_session.php
and write_session.php
.htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)?$ page.php?p1=$1&p2=$2&p3=$3 [L,QSA]
# www.example.com/parameter1/parameter2/parameter3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)?$ page.php?p1=$1&p2=$2 [L,QSA]
# www.example.com/parameter1/parameter2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php?p1=$1 [L,QSA]
#www.example.com/parameter1/
page.php
<?php
echo "Hello World";
// session_start();
// session_destroy();
?>
/test/session_define.php
<?php
session_start();
$_SESSION["session_test"] = "123456789";
?>
<a href="session_write.php">session_write.php</a>
/test/session_write.php
<?php
session_start();
echo "session_test:".$_SESSION["session_test"]."<br>";
?>
OK scenario:
Error Scenario (in page.php I uncomment "delete sessions"):
I am calling a specific php file (URL) in a subfolder and I thought that the condition could not be met:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ page.php?p1=$1 [L,QSA]
I don't understand how page.php can remove SESSION when I call PHP file "/test/session_define.php" directly. There should be no rewrite using .htaccess. In page.php, I have also intentionally stated: echo "Hello World"; but this doesn't show, only sessions are deleted.
Please what am I doing wrong? What am I getting wrong? Thank you very much for your help.
If a page doesn't explicitly specify the location of a favicon, some browsers try and request /favicon.ico
by default.
If you do not have such a file, this would trigger your last rule, and be rewritten to /page.php?p1=favicon.ico
. So your session gets destroyed by that request.