R
R
rinaz222020-11-09 19:15:33
PHP
rinaz22, 2020-11-09 19:15:33

I change the path through htaccess, but PHP still knows the original path. Why?

Hello! To shorten the url, I shorten it with htaccess:

RewriteRule ^([A-z0-9]{3,20})/archive/$ /pages/$1/files/archive/ [QSA]

Everything works fine, I enter page1/archive/ in the url , and the request is made to /pages/page1/files/archive/ . But there was a problem. PHP knows the original path.
In /pages/page1/files/archive/ there is a php file with the following code:
<?
print_r($GLOBALS);
?>

$_SERVER and $_ENV have the original path ( /pages/page1/files/archive/ ).
How to make it impossible to find out the original path through PHP, so that page1/archive/ is everywhere ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-11-09
@nokimaro

It's impossible to do so.
You can see the requested (short) path in $_SERVER['REQUEST_URI'], but the actual location from which the script was launched $_SERVER['DOCUMENT_ROOT'] $_SERVER['SCRIPT_FILENAME'] $_SERVER['SCRIPT_NAME']cannot be changed, since these values ​​are determined at the time of launch.
Although you can try one "feint with your ears" this is an indication auto_prepend_filein .htaccess
you make a script prepend.phpthat will be automatically loaded when you run any script and overwrite whatever you want in it.

php_value auto_prepend_file /www/server/prepend.php

ps as already written earlier - all this smacks of some kind of perversion and I do not know of a single case when I would have to do something similar in my scripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question