Hello everybody,
after searching the web for several hours to no result I hope my issue can be solved here.
We run a website www.example.com and want to have seo friendly search links such as www.example.com/search/hello+world
These should be rewritten to www.example.com/search.php?q=hello+world - we do this with this rewrite rule:
rewrite ^/search/(.*)$ /search.php?q=$1
This obviously works, only nginx seems not to decode the "+" sign (which is an urlencoded space character) but decodes all other urlencoded characters (%xx). So, for the given example $_GET['q'] in php does not contain "hello world" but "hello+world". This could of course be fixed by replacing the "+" with " " in php.
Now, if the search string also contains some encoded + sign (%2B, such as hello+world%2Bfriends) this results in $_GET['q'] to contain "hello+world+friends", so it is not possible to figure out what is an actual + and what was a space character. To give a more real world example, the search term could be "c++ book", which urlencoded is "c%2B%2B+book" but results in php $_GET['q'] as "c+++book".
Probably I miss something here, what setting/rewrite rule is needed to solve this? Shouldn't nginx decode "+" as well or pass the whole string unencoded (which seems not possible because it needs to decode for the regex to work).
Hope anybody can point me in the right direction, I would assume this is a quite common use of rewrite rules to make such links more seo friendly and human readable.
Thanks - Ralf
Edit: I know space can also be encoded as %20, but e.g. the firefox search bar plugin does it as "+", so it is not a matter of fixing it on the website only.
Edited 1 time(s). Last edit at 06/03/2010 03:19PM by Kleverhans.