Mobile app version of vmapp.org
Login or Join
Michele947

: ?cid= and ?pid= pages need to be fixed We have recently changed the platform and design of our website. Now I am having difficulty with url structure. Main product URL shows something like,

@Michele947

Posted in: #Php #UrlRewriting

We have recently changed the platform and design of our website. Now I am having difficulty with url structure. Main product URL shows something like,

/categories.php?cid=9


And internal product URL shows

/productdetails.php?pid=1


Now my question is, how can I fix the URL. I need a product name within the URL.

For example;

/productname1.php
/productname2.php


Don't care if the page is the main category page or product page.

What will be the URL rewriting code for category as well as product page?

Any suggestions?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Michele947

1 Comments

Sorted by latest first Latest Oldest Best

 

@Deb1703797

I'd go for the following structure:

/categories
/categories/23-foo
/categories/36-bar

/products
/products/124-examplename
/products/150-othername


I added categories/products in the url so you can differentiate between them, and this makes the url more obvious to what it does.
Also, I've added an ID in the url. This is an important thing! You should get the id from the url because:


It's always unique as you can use the Auto Increment value
Searching in your DB should be via integers as much as possible as it is WAY faster
Prevents the problem when two products are named identical (Brand A & B both use 'ThisName')
You can change the name/url of the product without rendering all your links useless


I prefixed the ID, if you want to postfix (e.g.: /products/example-123) you can do that.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme