HTACCESS URL Re-write

How do I retrieve the abc123 part of the URL below with .htaccess please?

https://a.com/product/abc123

I need to use the abc123 part to create a query. Ordinarily, I know this can be achieved with:

https://a.com/product/?key=abc123

and getting the abc123 part with $_GET like this:

$product_key = $_GET['key'];

but I would prefer the htaccess method, which I need help with.

Answer

put and play with this rule in your .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?product/(.*?)/?$ /index.php?key=$1 [L]

Leave a Reply

Your email address will not be published. Required fields are marked *