Clean URLs (possibly with slug)

I am using mongodb to store data. And the default _id is long and not-clean. So now my routes are like: example.com/job/sdg3463retgeragsehxcwe35435ert5

Works fine.

But is there any way to auto increment Numbers and save a custom ID (with a field name like, serial_number)?

I implemented it this way: Created another collection to store the last saved serial number. Then while saving a new data, increment it. This works fine, but is there any better way?

Also, how to save urls with slug instead of ids? Do I need a separate collection to store the slug and its relevant id?

What if I use raw mongodb _id? Is it going to hurt the SEO drastically? Or any other issues?

This works fine, but just wondering how the pros do it.

If you are willing to have alphanumeric ids the shortid module works pretty well. https://github.com/dylang/shortid

If you want actual slugs and are using mongoose you could try the mongoose-uniqueslus module. https://github.com/punkave/mongoose-uniqueslugs.git

  1. You should redirect all traffic to index.php using .htaccess
  2. On index.php you have to select what to do with the url ending, which is storeg in the $_SERVER["REQUEST_URI"] variable
  3. Depending on its value, you can show whatever you want :)

note: absolute links such as http://domain.com/index.php will continue to work unless you make some more changes in .htaccess.