Hi I had URLs like this…
www.example.com/list.php?type=vehicles&stype=Cars
www.example.com/list.php?type=vehicles&stype=Cars&loc=Ludhiana
And to sort results, sort variable was appending at last of URL and URL after adding sort variable was
www.example.com/list.php?type=vehicles&stype=Cars&sort='**ANYVALUE**'
www.example.com/list.php?type=vehicles&stype=Cars&loc=Ludhiana&sort='**ANYVALUE**'
And on href i was using
<a href="?<?php echo http_build_query(array_merge($_GET, array('sort' => 'sort-value'))); ?>"></a>
Above code was working perfectly for me. It was adding sort variable at end of URL as i want. Also it was modifying the value of sort variable if variable was existing already in URL.
But then i made my URLs SEO friendly and URLs now are
www.example.com/vehicles/Cars
www.example.com/vehicles/Cars/Ludhiana
After adding sort variable it becomes
www.example.com/vehicles/Cars&sort='**ANYVALUE**'
www.example.com/vehicles/Cars/Ludhiana&sort='**ANYVALUE**'
But now as URLs are SEO friendly, So when i use same href, it doesn’t work and it becomes
http://www.example.com/type=vehicle&stype=Car&sort=R-ASC
which results in a 404 error.
What will be the right href code so that it could do the following
- Append sort variable at the end of URL, whether the URL has 2 varibles or 3 variables.
- If sort variable already exists in URL, it will manipulate its value with current href.
Thanks in advance….
2
Answers
The first parameters char should be an ?.
I am not sure what do you need, but try something like that:
Random HTML form that gets the attributes and their values (like ?type=vehicle&stype=blabla) and redirects you to the page you want (pure HTML used, without any PHP):
Also if you want a link to the page instead of getting redirect
I hope i helped you less or more.