Suppose we have the following PHP page "index.php":
<? if (!isset($_GET['req'])) $_GET['req'] = "null"; echo $_SERVER['REQUEST_URI'] . "<br>" . $_GET['req']; ?>
and the following .htaccess file:
RewriteRule ^2.php$ index.php?req=%{REQUEST_URI} RewriteRule ^1.php$ 2.php
Now open access to "index.php". We get the following:
/index.php null
That's cool. Allow "2.php" access. We get the following:
/2.php /2.php
This is also cool. But now let's look at "1.php":
/1.php /2.php
So ... we ask for "1.php", it silently redirects to "2.php", which silently redirects to "index.php? Req =% {REQUEST_URI}", but here "% {REQUEST_URI}" seems to "2.php" (the page we are looking for after the first redirect), and $ _SERVER ['REQUEST_URI'] is "1.php" (the original request).
Should these variables be equal? Today I got a lot of headaches as I tried to make a redirect based only on the original request. Is there any variable that I can use in ".htaccess" that will tell me the original request even after the redirect?
Thanks in advance, and I hope I understand. This is my first post here :)
source share