Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Form method GET in SEO-Friendly URL schema
#1

[eluser]sirtea[/eluser]
Hello.

I'm trying to create a search page with codeigniter. Something like:

Quote:<form action="http://whatever.com/books/search" method="get">
<input type="text" name="query" />
<input type="submit" />
</form>

I expect to generate a URL like http://whatever.com/books/search/hamlet
and every user could use this kind of URL directly.

However, http protocol generates http://whatever.com/books/search?query=hamlet
I have read a lot of times about how to accept normal GET parameters, but I don't want this.
I want the HTML to pass directly the codeigniter-style URL.

I am looking at two possible solutions:
a) javascript onclick(), intercepting submit button and redirecting according to query
(concatenate the target URL on-the-fly/submit)
b) POSTing parameters to a fake method, who redirects at the concatenation of parameters

¿Any other idea?

Thanks
#2

[eluser]Buso[/eluser]
[quote author="sirtea" date="1281658809"]Hello.

I'm trying to create a search page with codeigniter. Something like:

Quote:<form action="http://whatever.com/books/search" method="get">
<input type="text" name="query" />
<input type="submit" />
</form>

I expect to generate a URL like http://whatever.com/books/search/hamlet
and every user could use this kind of URL directly.

However, http protocol generates http://whatever.com/books/search?query=hamlet
I have read a lot of times about how to accept normal GET parameters, but I don't want this.
I want the HTML to pass directly the codeigniter-style URL.

I am looking at two possible solutions:
a) javascript onclick(), intercepting submit button and redirecting according to query
(concatenate the target URL on-the-fly/submit)
b) POSTing parameters to a fake method, who redirects at the concatenation of parameters

¿Any other idea?

Thanks[/quote]
Both solutions will work fine. You can see the second solution in action on the site in my signature /search

Note: It's SEO-friendly, not CEO
#3

[eluser]Clooner[/eluser]
CEO-Friendly, LOL Big Grin
#4

[eluser]mddd[/eluser]
I have used both methods and like Buso says, they will both work.

Creating the url through javascript and redirecting there has the advantage that no POST request is done; this makes it easier if people are going to use the 'back' button: they will not get a message like 'are you sure you want to resend this form'. But is has the disadvantage that it will not work if people have javascript turned off.
#5

[eluser]sirtea[/eluser]
Finally I used the codeigniter-redirect schema.
I can't afford that my page does not work without javascript.
I will overrun the "reload POST" problem with a redirect.

search():
Code:
<form method="post" action="do_search">

do_search():
Code:
$var = $this->input->post('whatever')
redirect('search/'.$var);
#6

[eluser]Unknown[/eluser]
In a step forward, you can use both techniques.

Use JavaScript to avoid server load and, if JavaScript support is not enabled, the server will automatically redirect from an action to another one.
#7

[eluser]kkristo[/eluser]
And what you do, if search term is "my nice string"? or "company+ name"?
#8

[eluser]anupalusoft[/eluser]
these both method will create an issue if
1. we also want pagination which use URI segment but that can also be resolved with query string (per_page) so ok.
2. for advance search where user put only those which he want to search like in case of filter. where we can't determine which uri segment is what parameter

Any solid solution for it guys ?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB