The term you want to research is search engine friendly URLs, most often accomplished with Apache’s ModRewrite.
You will need to change your DB to also store the URL segment (e.g topic_title_2) so can find the page or article based on that, instead of the numeric ID.
It looks like all your current URLs use index.php?
An example .htaccess file (Apache configuration) might look like this:
RewriteEngine On
RewriteRule category/([a-zA-Z0-9\\.\\_\\-]+)/?$ index.php?category=$1
RewriteRule topics/([a-zA-Z0-9\\.\\_\\-]+)/?$ index.php?topic=$1
With this a request for category/books will point to index.php?category=books (the address bar won’t change, but index will have $_GET[‘category’]).
You’ll then need to lookup your DB for the correct content.
If you have a CMS for adding items to the DB it will need to create a unique URL segment for each record.
This might seem radical but you could just change your database.
From:
Categories
cat_id 149
cat_title ‘Local News’
To
Categories
cat_id ‘local-news’
cat_title ‘Local News’
Or just plain
Categories
cat_title ‘Local News’
(Then be prepared to lowercase and ‘slugify’ the title e.g. “Local news” might be your nice Title on page, whereas ‘local-news’ might be your slug)
Now of course you have to change your dependent tables too.
Here is an old long and rambling post of mine if you are interested in why/how this can be done and the benefits, and also introduces some terms which might be new to you.
Basically, you want to do away with having a script which has to decipher 149 to discover its real meaning “Local News”, but you should continue on with it if you feel the database solution is over the top.
Personally I’m not that keen on automatically converting local-news to Local News, because it’s hard to know when a dash is a substitute for a space, or when it really was supposed to be part of the title.
With a lookup there’s no confusion. The primary key could be a string field though.