![]() |
how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? (/showthread.php?tid=36702) |
how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-11-2010 [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. how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-11-2010 [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... how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-11-2010 [eluser]stuffradio[/eluser] Code: $route['search/(:any)'] = 'search/$1'; how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-11-2010 [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) how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-12-2010 [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. how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-12-2010 [eluser]Twisted1919[/eluser] Code: <form action="" method="post" id="theForm"> how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-12-2010 [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"> how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-12-2010 [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 ![]() how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-12-2010 [eluser]Michael Wales[/eluser] Code: class Search extends Controller { how to create a www.example.com/search/keyword keyword is $_POST['search']; anyone? - El Forum - 12-14-2010 [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=''){ |