-3

My URL is looking now like this:

localhost/en/products/bear-toys/bear.php?id=26123

And i need to looks like this:

localhost/en/products/bear-toys/bear/26123

or if i can get title of that product and store into URL:

localhost/en/products/bear-toys/bear/blue-bear.php

I know there is solution with .htaccess but im not good one in .htaccess. So any kind of help will be good. Thanks all

Mark
  • 25
  • 5
  • Is there always 4 elements to your query string or do you want to have different lengths after products/ ? – blupointmedia Oct 21 '19 at 22:07
  • I need to have this `en/products/product-category/sub-category/` then product and best solution for me now is to get title of product @blupointmedia – Mark Oct 21 '19 at 22:13
  • It might help to show what you've got in your `.htaccess` file so far and let us know what specifically goes wrong. – showdev Oct 21 '19 at 22:27
  • In my htaccess i have only what `blupointmedia` post as answer @showdev – Mark Oct 21 '19 at 22:30
  • I see, okay. To generate more answers, it may help [do a little research and make an attempt](https://stackoverflow.com/help/how-to-ask). Otherwise people might feel like they are just writing free code. Here are some ideas about how to get an item's id from its name: [show product name in the url but call the product with the id](https://stackoverflow.com/a/22417005/924299) and [mod_rewrite with name replacing ID](https://stackoverflow.com/a/21218043/924299). – showdev Oct 21 '19 at 23:08

1 Answers1

1

If you want everything after products you can do something like this in htaccess and in PHP. products.php can be the page you want to write to to accept the param(s)

RewriteEngine On
RewriteRule ^(.*)/products/(.*)$ product.php?lang=$1&q=$2 [L,NE]

and this in PHP

$lang = $_GET['lang'];
$params = explode('/', $_GET['q']);

echo $lang . '<br>';
var_dump($params);
blupointmedia
  • 564
  • 2
  • 10