The implementation is based on the single entry point principle, the contents of the address bar are broken down $routes = explode('/', $_SERVER['REQUEST_URI']) and the results are passed to the handlers.
The address bar has the following form: example.com/11/20 , where 11 is the user id and 20 is the category id.
Entries in .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L] There was a problem adding a slash to the end of the line. For example, addresses of the type work correctly.
example.com/11 example.com/11/ example.com/11/20 but the problems start when I try to add a slash (and an additional variable) to the end of the line:
example.com/11/20/ example.com/11/20/page3 In this case, the index page "loses" css styles, js libraries and display images.
Someone can explain why adding a slash breaks the page, and most importantly, why it happens at a certain level of nesting (for example, you can add a slash like this - example.com/11/ - you can still, and so - example.com/11/20/ - already impossible)? Is this somehow fixable?
UPD.
All routes are routes the same way, i.e. in all cases, index.php loaded, and the variable is assigned the value resulting from parsing the string:
if(!empty($routes[1])) { //если это не главная страница всего сервиса if(intval($routes[1])) { //если это страница пользователя, а не, например, поиск $user_id = intval($routes[1]) ; if (empty($routes[2])) { //если запрос главной страницы или категории (не контакты, не поиск ...) require "html/index.php"; //some code require "html/index.php"; $page = $routes[3]; The problem is partially solved by the fact that in the loadable index.php in the lines of the form href = " .. /css/style.css" removed the transition to the level up, i.e. replaced by href = "/ css / style.css" (no dots ahead). I wrote “partially solved” , because now the code works with something like a slash and without it, but I don’t understand the reasons for this behavior and such selectivity (for the code I ask you not to kick).
routesget one more element than usual. But how this affects the logic of further processing from the text of the question is not clear. Study the code, see what happens when a single empty element is added to the routes. - teranВ этом случае index-страница "теряет" стили css, библиотеки js и отображаемые изображения.generate absolute addresses for them, not relative ones. - Visman