-4

Can anybody advise how I can rewrite the following URL:

www.mydomain.com/products.php?product=product-name

At the moment, it works fine (I use $_GET to grab the unique product name and use it on my page) but I would like to be able to use the following URL format to get the same outcome:

www.mydomain.com/products/product-name

I've seen a few similar examples on here but cannot get them to work with my situation.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
mckeegan375
  • 255
  • 4
  • 14

1 Answers1

1

This is how your .htaccess will look like,

RewriteEngine On
RewriteRule    ^products/([A-Za-z0-9-]+)    /products.php?product=$1    [NC,L]

RewriteEngine On this is used to turn on the rewrite engine.

^products/([A-Za-z0-9-]+) matches the URL like (www.mydomain.com/products.php?product=product-name) where product name can be one or more of any combination of letters, numbers and hyphens.

And use that combination of letters in /products.php?product=$1 where $1 denotes the Product name.

Alok Patel
  • 7,842
  • 5
  • 31
  • 47