Setting up routing in CodeIgniter

Good day to all… I have a question, how to implement the following:
there is a link like http://site.ru/news?id=[news-id]and you need to change it so that the link works at http://site.ru/[news-id]Displaying via http://site.ru/news?id=[news-id]is already done. Thank you.


Answer 1, authority 100%

Try adding the following to your routes.php file:

$route['(:num)']  = 'news?id=$1';

meaning $1is [news-id]

Where is the link to

news?id=[news-id]

Replace with

[news-id]

If this doesn’t work, maybe the .htaccess file at the root of the site should contain these lines?

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|demo|files|js|recommend|products|partner)
RewriteRule ^(.*)$ /index.php?/$1 [L]