The site consists of only one page index.php. The structure of the site is contained in the database and should be presented to the user in a hierarchical form:

имя_сайта\каталог1\каталог2\....\каталогN 

The number of directories and the number of levels of investment is unlimited. The user can delete a part of the address to the i-th directory in the browser line and get information on this directory.

I implemented this problem statement using .htaccess

 RewriteEngine on RewriteRule ^([a-zA-Z0-9_/]+)/([a-zA-Z0-9_]+)$ index.php?catalog_name=$2 [L] 

That is, I use the GET method as the catalog_name parameter to name the last directory, look for it in the database and enter information from the database on it.

The problem is that when the user types in the address bar of the browser

 имя_сайта\каталог1\каталог2\....\каталогN 

After the server executes the RewriteRule command

The address bar in the browser for the user changes to index.php?catalog_name=каталогN (although it remains the same in some servers), which is inconvenient for the user.

I would like to address

 имя_сайта\каталог1\каталог2\....\каталогN 

In the browser line for the user after the execution of the RewriteRule did not change and the user did not know that there is

 index.php?catalog_name=каталогN 
  • If the proposed answer resolves your problem, please accept it (checkbox to the right of the text) - this is the custom on this site. If not, ask clarifying questions. - Nick Volynkin

2 answers 2

I'll try to answer: we rewrite the .htaccess file:

 RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)$ ./index.php?route=$1 

This will give us the $_GET['route'] variable that will contain everything after / . Then we work in index.php - parsim this variable into components, and give the user what he needs. The address bar should not be changed.

  • On the meta speech about this issue? - Nick Volynkin

@Shilgen, you are right. Everything worked out. Only I did a little differently.

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?route=$1 

Thank.