0

I'm trying to achieve this in Codeigniter. I have got a URL like below

https://www.example.com/5474/my-first-post

I'll be processing this URL using the id and get the blog content from this id. but I don't want to show the ID in the URL.It should be like below.

https://www.example.com/my-first-post

I'm doing this because previously I was getting the blog content using the title. But that makes the website very slow when there are a lot of rows in the database (It takes around 5 seconds roughly on the local server).Where as I tried the same using the ID. I was getting the row from database using the ID. It takes very less time like say 0.0007 seconds. Any solution to this is highly appreciated.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
Jeeva
  • 632
  • 1
  • 12
  • 21
  • you can prefer this link for your reference URL : https://stackoverflow.com/questions/25723183/php-hide-id-from-being-shown-in-a-href-url – NikuNj Rathod Sep 07 '17 at 07:03

3 Answers3

0

You can use

uri-routing

Example:

$route['my-first-post'] = 'your_controller/your_function';
Community
  • 1
  • 1
always-a-learner
  • 3,671
  • 10
  • 41
  • 81
  • how will this call the row with the id. – Jeeva Sep 07 '17 at 08:13
  • Hi @Jeeva if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – always-a-learner Sep 12 '17 at 10:57
0

This is too hard to do routes for each url.

add a field in your table..

ID | url | post_title
33 | hello-world | Hello World.

Then use that url text on behalf of id

Bira
  • 4,531
  • 2
  • 27
  • 42
  • I'm doing it same way. But it is very slow for large table. So i wanted to do it with id and the id should not be there in the url – Jeeva Sep 07 '17 at 08:13
0

convert your numeric id using base64_encode()

Akshit Ahuja
  • 337
  • 2
  • 15