You could do this with your .htaccess file.
For that you need to write in your .htaccess:
RewriteEngine on
RewriteRule ^search/([A-Za-z0-9\-]+)/?$ search.php?q=$1
The first line activate your RewriteEngine, so you can write RewriteRules as much you like.
In the second line you define your first RewriteRule:
In the URL it need to be search/([A-Za-z0-9\-]+)/
.
That means, you only allow the characters inside the square bracket.
Then you redirect to your wanted script, in this case its search.php
with the GET Parameter.
It's also possible to do this with more parameters or much more. For that you should google maybe "htaccess Explanation".
array_pop (explode ("/",$_SERVER['HTTP_HOST']))
will give you test when the url ishttps://example.com/search/test/
. In your index explode the whole url and call the right php file in function (with a switch)