URL Best Practice

I’m struggling to find the best method for setting my URL. I have a recipe app, and I am trying to set the URL of the page that displays the recipe.

Because I have multiple users posting recipes, I expect that there will be duplicate recipe names. I don’t think slugs will work because they do not allow duplicates, and I would rather not append numbers after each duplicate.

My current idea is to set the url to something like this: mywebsite.com/recipe/user/recipename. However, I’m not sure the best way to add multiple path segments (the user and the recipe name). Maybe there’s a better way to approach this, and I’m open to suggestions.

I started working with Zeroqode’s URL Router plugin and it does great in terms of setting the URL on page load. My concern there is making that link shareable (i.e. if someone shares the routed link, it doesn’t actually navigate to a real page). My next thought would be to maybe Do a Search For Recipe, where the user and recipe name are extracted with Regex from the URL, but I don’t know if that’s the best approach.

That should be doable…

For your datasources on the page you’ll need to search the database for both Users and Recipes, and match them to the URL segments.

I’m assuming you aren’t going to be using unique IDs in the URL so you’ll still need to ensure the URL contains a unique identifier (at least for the User)…

Then you’ll need to do a search for Users who’s name (or whatever is in the URL) matches the data from the URL.

Then do a search for recipes, who’s name matches the URL, and who’s User matches the User.

So I’ve got it basically working. On page load I change the URL router. If the current page recipe is empty, I do a search for recipe using the path segments as list (user’s slug and recipe’s name). Now, my concern is the page load time. It took about 3.5 seconds, but I imagine that this will only get worse as the user and recipe base grows.

I don’t know anything about the URL Router plugin (or why you’re using it here…), so the slow page load time could be to do with that… I can’t really comment on that…

But I can’t see why searching for data based on the URL path should be any different than using a unique ID or slug (it’s basically the same thing?..)…

Certainly, in my experience, I’ve not noticed any difference between using slugs or manually searching the database to match URL paths - but I’ve not tried it with very large datasets.

My hope with the URL router is that I can have users have the same name for recipes without having to append numbers like slugs do (mywebsite.com is available for purchase - Sedo.com rather than mywebsite.com is available for purchase - Sedo.com). But if there’s another approach then I’m open.

I think the page load time is just a product of the page having to re-load and display the recipe. I’m thinking that this thread might work if I can re-route the navigation up front and prevent the page from having to load twice.

This topic was automatically closed after 70 days. New replies are no longer allowed.