Beautiful links with NO id

I am considering my options for implementing good links for a new website.

I understand how to get the basics to work, for example:

/ view / postTitle / 7895

I can just select id 7895 and just ignore the header.

However, I see that some sites manage to get rid of IDs completely:

/ view / postTitle

How it works?

The only way I can think of is that on every request, the pageTitle is sent as a string, and some code does some SQL validation to return the correct id. However, would that mean a lot of potentially expensive SQL queries? Especially when you have a lot of messages.

It also means that every time someone creates a post, I need to create a unique URL-friendly string for that post. I need to check the database until I get a unique one. It looks like too much.

Am I looking at this the wrong way? Or are there ready-made APIs and tools to make it easier and more efficient?

I am using PHP / MySQL, Apache.

thank

+2


source to share


3 answers


Create a function that normalizes / deactivates message headers. An easy way could be the urlencode () hash representation of the original title. Store this as "id" instead of the numeric value generated by the db and your SQL doesn't need much change.



+2


source


You're right. There are two aspects you have to deal with.

First, when someone posts a message, you have an html friendly url to add to each of the links. Really, it's not too difficult. You need to replace spaces, special characters, etc. Basically, any win you make for database storage is a good starting point. You also need to make sure they are unique.



Second, when someone clicks on your site using a link, you need to resolve it correctly. It's a little more complicated, but can effectively work the same way if you think that every uniquely generated URL is an identifier, because, in essence, it becomes ... if you ask for it (escaped, of course!).

For a reliable implementation, most CMSs - WordPress and Drupal come to mind - handle this fairly efficiently. Coming from a Drupal background, I would suggest that you look at the "path" and "path" modules as it is done with an emphasis on "path" ... it covers both halves of the problem.

+1


source


You have the right approach. Generally, if it's a simple messaging CMS, use a package like WordPress and modify it to suit your needs. If you have custom datatypes, I highly recommend SilverStripe, and if you want to use users, use Drupal. There are libraries and functions floating around that can convert the post title to a URL, which would also be a good idea to explore. Open-Source works great and you can see how others have done it, try to find github etc.

0


source







All Articles