The site uses CNC, all requests are transmitted to index.php. At the moment, the following entries are present in htaccess:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L] 

Nothing tricky, and therefore works fine. But there is a small problem - the mandatory presence of a slash at the end of the URL. The URLs of only two types: http://site.ru/part_1/part_2/ (the slash is needed at the end ) and http://site.ru/part_1/part_2/?param=something ( slash, of course, is not needed ) . In the first case, if the URL was entered, for example, by the user manually and without a slash at the end, it must be added. Of course I can do the PHP checks already when processing the request, but I would like to humanize it somehow. I would be grateful for the help.

    2 answers 2

    I implemented in PHP .

     $exp = explode('?', $_SERVER['REQUEST_URI']); if ( mb_substr($exp[0], -1) != '/' ) { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $exp[0] . '/' . (!empty($exp[1]) ? '?' . $exp[1] : '')); exit(); } 
    • Yes, this is probably an option, tk. I can assume that the mod_rewrite rule will do almost the same thing. If this is so, then it is possible that you should not bother with htaccess - Deonis
      RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !/$ RewriteCond %{REQUEST_URI} !.html$ RewriteRule (.+) $1/ [R=301,L]