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