views:

152

answers:

3

I'm dealing with two question marks in a single entry website.

I'm trying to use urlencode to handle it. The original URL:

'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'

I want to use it in the single entry website:

'index.php?page='.urlencode('search?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1')

It doesn't work, and I don't know if I must use urldecode and where I can use it also.

Do you have any suggestion?

+1  A: 

Why not just rewrite it to become

index.php?page=search&query=...

mod_rewrite will do this for you if you use the [QSA] (query string append) flag.

http://wiki.apache.org/httpd/RewriteQueryString

Ilia Jerebtsov
What makes you think mod\_rewrite can solve this problem?
Gumbo
It doesn't solve that specific problem, but merging the two query strings into one is a trivial rewrite that would avoid the entire problem altogether, and keep him from having to manually parse a second query string.
Ilia Jerebtsov
What happens if he's running on IIS or another non-apache server?
ChronoFish
IIS has its own rewrite modules. Here's one: http://www.isapirewrite.com/
Ilia Jerebtsov
@Ilia: The IIS question was rhetorical. mod_rewrite is great for many things (clean URLS etc). But the code should not depend on on it and should work fine without the mod_rewrite. The point of my question was to encourage a server-independent solution.
ChronoFish
Ilia Jerebtsov
ChronoFish
mod_rewrite isn't a tool to turn query strings into directory paths, or an URL beautifier. It's a generic tool for URL manipulation. I'm recommending this because he seems to be implementing some sort of controller routing scheme ("single entry website"). Instead of using the whole URL as a key and manually parsing out the "second" query string, he could much more easily key on "search" and let mod_rewrite merge the query strings for him, so that he can access them in $_GET as usual.
Ilia Jerebtsov
A: 

$_SERVER['QUERY_STRING'] will give you everything after the first "?" in a URL.

From here you can parse using "explode" or common sting functions.

Example:

http://xxx/info.php?test=1?test=2&test=3

$_SERVER['QUERY_STRING'] =>test=1?test=2&test=3

list($localURL, $remoteURL) = explode("?", $_SERVER['QUERY_STRING']);

$localURL => 'test=1'

$remoretURL =>'test=2&test=3'

Hope this helps

ChronoFish
A: 

I would suggest you to change the logic of the server code to handle simpler query form. This way it is probably going to lead you nowhere in very near future.

Use

index.php?page=search&query=...

as your query format but do not overwrite it with mod_rewrite to your first wanted format just to satisfy your current application logic, but handle it with some better logic on the server side. Write some ifs and thens, switches and cases ... but do not try to put the logic of the application into your URLs. It will make you really awkward URLs and soon you'll see that there is no lot of space in that layer to handle all the logic you will need. :)

ivanjovanovic