I have a question, i want to make some search page, and it needs a get variable to sort the results. So if someone enters the page without that GET variable, reload the page and make it appear, for example you enter www.myweb.com/search and automatically reloads and changes to www.myweb.com/search/?sort=ascending (because that variable is necessary) .
I hope you understand me, good bye
It is better to define the variable by yourself rather then redirecting. Just check with isset if the variable is defined or not. It it has not been defined you can set it yourself as below.
From within the file executed when
www.myweb.com/search
is requested, you should have a default setting when $_GET['sort'] isn't available. For this Answer, I'll be using PHP for my examples since you didn't specify.Alternatively, you could force a redirect, but the previous example is more elegant.
Keep in mind, the second solution would throw away anything else, i.e., other $_GET's, like
item=widget
orcolor=blue
Note to others posting
!isset
as an answer. That will not work! Example:!isset($_GET['sort'])
=== false!empty($_GET['sort'])
is the proper route to take in this circumstance.I think this will work for what you're looking to do: