0

i am trying to convert these urls

localhost/list/data/?search=keyword
localhost/list/data?search=keyword

to

localhost/list/data/search/keyword

i used this expression

(.+)(\?|\/\?)([a-z0-9_-]+)=([a-z0-9_-]+)

the problem is suppose that the user searches for another keyword

localhost/list/data/search/keyword/?search=anotherkeyword
localhost/list/data/search/keyword?search=anotherkeyword

it becomes like this

localhost/list/data/search/keyword/search/anotherkeyword

how can make it like this

localhost/list/data/search/anotherkeyword

where in it replaces the previous search/keyword in the url

kapitanluffy
  • 1,269
  • 7
  • 26
  • 54

1 Answers1

0

Its a little more complicated than just regex. The best approach is a combination of server side scripting, and htaccess. I wrote up an answer for a very similar question not to long ago. As well as use this solution in a handful of sites I develop.

PHP dynamic DB page rewrite URL

Ill save the time from rewriting the post I made on the above link and just let you use that as your guide, hope it helps

Community
  • 1
  • 1
chris
  • 36,115
  • 52
  • 143
  • 252