Home > Software engineering >  Create new productpage when new database entry
Create new productpage when new database entry

Time:05-16

How can I create a new page when I enter a new product in my database, or hide the parameter inside a normal /.../ ?

In this example I will sell Sandles with the product-id 101010

I do not want to use parameters like in the following example:

example.com/shop?productid=101010

But I would like the new page to be

example.com/shop/sandles

CodePudding user response:

First of all you'll need be able to fetch product not by some numeric ID (101010), but by url segment like this 'my-unique-product-name' (upgrade your server side code)

Now you should have something like this working:

example.com/shop?url=my-unique-product-name

then add to your .htaccess something like this:

RewriteRule ^shop/([A-Za-z0-9-_] ])$ shop.php?url=$1 [L]

It tells your server to process URL-s like example.com/shop/my-unique-product-name in a same way as example.com/shop?url=my-unique-product-name, if that makes sense to you.

Read more about .htaccess URL rewrite here

  • Related