AnchovyLegend
AnchovyLegend

Reputation: 12538

Implementing a slug / clean URL system - general plan

I am currently working on a eCommerce style project that uses a search engine to browse 7,000+ entries that are stored in a database. Every one of these search results contain a link to a full description page. I have been looking into creating clean/slug URLs for this, my goal is if a user clicks on some search result entry the browser will navigate to a new page using the slug URL.

www.mydomain.com/category/brown-fox-statue-23432323

I have a system in place to convert a string / sentence into URL form. However, it is not clear to me what the proceeding steps are once these URL's are created. What is the general plan for implementing this system? Do the URL's need to be stored in a database? Am I suppose to be using post or get data from the search result page to create content in these full description urls?

I appreciate any suggestions!

Many thanks in advance!

Upvotes: 0

Views: 816

Answers (3)

RandomSeed
RandomSeed

Reputation: 29769

A common approach is to have a bijective (reversible) function that can convert a "regular" URL into a user-friendly URL:

E.g.:

www.mydomain.com/category/brown-fox-statue-23432323

<=>

www.mydomain.com/index.php?category=brown-fox-statue-23432323

Then you need not keep record of this mapping (convention vs. configuration).

Search StackOverflow for "User Friendly URL Rewriting" for information on how to achieve this automatically with Apache. This question is a good starting point.

Upvotes: 0

amamut
amamut

Reputation: 311

Maybe you can enlighten us as to if you are using a framework? Some frameworks (like Zend) have ini / xml files for routing. But you will still need to store the urls or at least the article slugs in a db.

Storing the entry urls in the db after they have been "searched" is necessary because you want slugs to stay the same for entries. This allows for better caching / SEO which will improve your sites usability.

Hope that helps!

Edit: Saw your question about pulling up individual articles. You will have to start by setting up a relation between your entries to urls in your database. Create a url table with url_id, and url. Then place url_id on the entry table. Then whenever someone goes to any URL search the url table for the current url, recall the url_id, and then pull the entry. At that point its just styling the page to make it look the way you want.

Upvotes: 0

Anigel
Anigel

Reputation: 3437

Each product has a unique url associated with it in the database.

When you perform a search you just return the correct unique url.

That way you only ever work out what the url should be once, when the product is first added and that url will always relate to that one product. This is the stage you use your system to create that url

Upvotes: 1

Related Questions