Using regex: php clean urls using regex on newest questions tagged regex – Stack Overflow

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

See Answers


source: http://stackoverflow.com/questions/11731943/php-clean-urls-using-regex
Using regex: using-regex



online applications demo