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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.