The site structure is as follows:

site.ru/users/ - user list site.ru/users/user/2 - user with ID2

If after the ID, I put a slash (/) and I add any value, then this page also opens. Example:

site.ru/users/user/2/

site.ru/users/user/2/dasd

site.ru/users/user/2/dasd/dasd

site.ru/users/user/2/dasd/dasd/dasd

When you open any link, the page content opens - site.ru/users/user/2/, i.e. we actually have duplicate pages.

The same is true in articles (you can even substitute any value without a slash):

site.ru/articles/articles-title

site.ru/articles/articles-title/dasd

site.ru/articles/articles-titledasd

site.ru/articles/articles-titledasd/dasd

site.ru/articles/articles-title/dasd/dasd

etc.

What can be done so that when opening such pages there is a 404 error? Those. if you open the site.ru/users/user/2 page, it gives the content. If you open the site.ru/users/user/2/xxx page, you get an error 404.

Thank.

    2 answers 2

    At random it turned out to be solved like this:

    Added to the routes.php file:

    $route['users/user/(:num)(:any)'] = '404_override'; 

    Now, if at the end of the link to insert non-existent data, gives 404 error

    site.ru/users/user/2/ - OK

    site.ru/users/user/2/dasd - 404

      I can somewhere be wrong, but in general you can catch it in php like this:

       $url=parse_url($_SERVER["REQUEST_URI"]); $path=$url["path"]; $patharray=explode("/", $path); if (($patharray[0]=="users") and (count($patharray>=4)) or ($patharray[0]=="articles") and (count($patharray>=3))) { header('HTTP/1.0 404 Not Found'); //код 404 страницы exit(); } 
      • Thanks for the answer. A bit does not fit here, but take note. - kate