0

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!

AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231

3 Answers3

1

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

Anigel
  • 3,435
  • 1
  • 17
  • 23
  • Thanks for the reply. So, once a URL is stored in the database for product X, how can I use this URL to create a corresponding full description page on the fly so I can put this URL to good use? In other words, the `href` attribute of the link would be this new URL's right, but this page does not physically exist yet, this is where I am stuck... – AnchovyLegend Jul 08 '13 at 14:29
  • How do you create a product page at the moment? All this url is, is a pointer to the product page. – Anigel Jul 08 '13 at 14:33
  • Well it isn't created at the moment, I am trying to come up with a simple way to create it, preferably on the fly. All product pages are going to be very short/simple with about 7-8 pieces of information that can easily be passed using Ajax / GET / POST, any suggestions? – AnchovyLegend Jul 08 '13 at 14:56
  • Randomseeds answer above gives you a good starting point for how to dynamically generate a page on the fly. – Anigel Jul 08 '13 at 14:58
0

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.

amamut
  • 311
  • 1
  • 7
  • The url should be consistent, but you don't have to hold on to the whole URL necessarily. Having a slug and tack on something like unique name + product_id from the database will work just as well – Ikstar Jul 08 '13 at 14:35
  • Yes you don't have to store the URL for a single site. But if you are working with a multi-site app you will have to. – amamut Jul 08 '13 at 14:36
  • @amamut, Thanks for the reply! Reading.... `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.` However, I am still confused as to how to create a link to a page that doesn't exist? Lets say the link is `mydomain.com/brown-fox-statue-123423` this `.php` file does not currently exist. Once clicked, the address will change to this URL for a page that does not exist. Can you please clarify? – AnchovyLegend Jul 08 '13 at 15:02
  • I am not sure if you are using a framework but all frameworks allow you to route uri's (/category) to a particular controller (or php file). If you are not using a framework everything will go through your index.php file. At which point you will have to get the `$_SERVER['REQUEST_URI']` and see if it has the word "category" in it. If it does then parse the `$_SERVER['REQUEST_URI']` to pull the entry name (brown-fox-statue-23432323). Then do a DB lookup for the entry and display it. Very quick and dirty but its the best I can do with the information you have given me. – amamut Jul 08 '13 at 15:09
0

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.

Community
  • 1
  • 1
RandomSeed
  • 29,301
  • 6
  • 52
  • 87