-2

Assume that i'm having a URL like this

example.com/demo/index.php?name=test

Now I need to rewrite the above URL like this,

example.com/demo/test

My question is, how can I achieve that by .htaccess URL rewriting?

RavinderSingh13
  • 101,958
  • 9
  • 41
  • 77

2 Answers2

0

yuppp, I got it

RewriteRule ^demo/([\w-]+)$  demo.php?id=$1

Credit to : @Abhishek Gurjar

  • Please consider using the real http server's host configuration to implement such rules instead of distributed configuration files (".htaccess"). – arkascha Nov 04 '20 at 12:25
  • @arkascha can you please deeply tell me for how to better access this – Bhavik Gajjar Nov 04 '20 at 12:30
  • Want to keep example.com/demo/index.php?name=test test name in every link like example.com/demo/test/product/12 – Bhavik Gajjar Nov 04 '20 at 12:32
  • Although this does not do quite what you were asking in the question? – MrWhite Nov 04 '20 at 14:35
  • The rule is perfectly OK, though variants or alternatives exist. But the apache http server offers different locations where to implement such a rule. Usually the better location is _not_ distributed configuration files (".htaccess"), but the real host configuration, for a number of reasons. Maybe you want to read a bit about that in the documentation. It is just a suggestion, what you do here will work. – arkascha Nov 04 '20 at 16:48
0
RewriteEngine On
RewriteRule ^test/(.+) /test.php?name=$1 [L]

you must add bove code in htaccess and you can get parameter as $_GET['name']

Shantun Parmar
  • 394
  • 1
  • 10