how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? |
[eluser]dudel[/eluser]
Hello everybody ![]() So, I'm new and I'm stuck with uri routing. Basicaly, all I want to do is add a keyword after the search in the url. I`ve put this two lines into index function of the controller : Code: $query = rawurlencode($this->input->post('search')); and this line in the routes file Code: $route['search/?(.*)'] = 'search/$1'; I have a form on www.example.com. when i type something in the input text i want it to appear after the "search" in the url. like this www.example.com/search/keyword. Does anyone have any suggestions? Thank you.
[eluser]richthegeek[/eluser]
You can use a mod_rewrite rule to redirect (full http redirect [R=302], not just an infile redir) from /search?q=some+value to /search/some+value quite easily, and then use a route to go from /search/(.*) to /search/query/$1 or whatever. Seems a little complex "just" to get a neater URL out of it, tbf...
[eluser]richthegeek[/eluser]
stuffradio - the problem isn't the internal routing, but going from a form to a slash-delimited URL, which can only be done with htaccess or javascript (or both, for graceful degradation)
[eluser]dudel[/eluser]
Hello and thank you for your responses. Do i need to create a htaccess file in the controller`s directory and add this line in it or add it to the default htacces file from the root? How do I redirect from htaccess? RewriteRule ^search/(.*)$ search/$1 [R=302] I`m trying this and it doesn`t work. Thank you, again.
[eluser]Twisted1919[/eluser]
Code: <form action="" method="post" id="theForm">
[eluser]richthegeek[/eluser]
Twisted1919: perfect except for the 5% (overzealous figure) of users who have JS disabled for some arcane reason. The apache rewrite is the fallback for this, and should work as this (not tested): Code: RewriteRule ^search/(\?[^=]*=(.*))?$ search/$2 [R=302,L] Your form open tag would be like so in this case, to allow the fallback to work before being overwrriten Code: <form action="<?=site_url('search');?>" method="get" id="theForm">
[eluser]dudel[/eluser]
Yeah, I don`t really know why there are people out there with JS disabled. Thanks for the informative replys. Enjoy your sunday ![]()
[eluser]Michael Wales[/eluser]
Code: class Search extends Controller {
[eluser]Cesar Kohl[/eluser]
I don't know if it's exactly what you need, but to search I made this controller: Code: function search($keyword=''){ |
Welcome Guest, Not a member yet? Register Sign In |