CodeIgniter Forums
Routes and GET Query. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Routes and GET Query. (/thread-33127.html)

Pages: 1 2


Routes and GET Query. - El Forum - 08-16-2010

[eluser]pisio[/eluser]
How I can make GET doesn't like this
http://localhost/ci/subtitles/search?subs=sads
and like this
http://localhost/ci/subtitles/search/subs/sads
or
http://localhost/ci/subtitles/search/sads


I try to add in
./system/application/config/routes.php :
$route['subtitles/search/(:any)'] = "/subtitles/search/$1";

But doesn't work.
How I can make it ?
searach_view.php

Code:
<?php
$lang = $this->lang->language;

echo form_open('/subtitles/search/',array('method' => "get"));
echo $lang['search'].form_input(array('type'=>'text', 'name' => 'subs'));

echo form_input(array('type'=> 'submit','value'=>$lang['go']));
echo form_close();

?>


Edit:
I think that can be made with .htaccess mod_rewrite ?????


Routes and GET Query. - El Forum - 08-16-2010

[eluser]WanWizard[/eluser]
Looks like you're constructing the URL yourself in your form. Why not use the 'post' method, and accept a URL like http://localhost/ci/subtitles/search/subs/sads directly?


Routes and GET Query. - El Forum - 08-16-2010

[eluser]pisio[/eluser]
[quote author="WanWizard" date="1282009785"]Looks like you're constructing the URL yourself in your form. Why not use the 'post' method, and accept a URL like http://localhost/ci/subtitles/search/subs/sads directly?[/quote]
More impression. And If i can make it with GET I'll make it with redirect ...


Routes and GET Query. - El Forum - 08-16-2010

[eluser]WanWizard[/eluser]
Sorry, I don't understand what you're trying to say...


Routes and GET Query. - El Forum - 08-16-2010

[eluser]pisio[/eluser]
[quote author="WanWizard" date="1282010159"]Sorry, I don't understand what you're trying to say...[/quote]
If I can not do it with GET to go / subtitle / search / what is demanded to do what you offered me a redirect.No afraid of too many impressions


Routes and GET Query. - El Forum - 08-16-2010

[eluser]WanWizard[/eluser]
You can try this rewrite
Code:
Rewritebase /ci/
RewriteCond $1 ^subtitles/search/$
RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
RewriteRule ^$ subtitles/search/subs/%1 [L]



Routes and GET Query. - El Forum - 08-16-2010

[eluser]pisio[/eluser]
[quote author="WanWizard" date="1282011132"]You can try this rewrite
Code:
Rewritebase /ci/
RewriteCond $1 ^subtitles/search/$
RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
RewriteRule ^$ subtitles/search/subs/%1 [L]
[/quote]
Code:
<IfModule mod_rewrite.c>

        Options +FollowSymLinks
        RewriteEngine on
        # Send request via index.php (again, not if its a real file or folder)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d

        <IfModule mod_php5.c>
                Rewritebase /ci/
                RewriteCond $1 ^subtitles/search/$
                RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
                RewriteRule ^$ subtitles/search/subs/%1 [L]

                RewriteRule ^(.*)$ index.php/$1 [L]
        </IfModule>                                    
</IfModule>

error 500


Routes and GET Query. - El Forum - 08-16-2010

[eluser]WanWizard[/eluser]
This one works for me:
Code:
RewriteCond $1 ^subtitles/search$
RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
RewriteRule ^(.*)$ $1/subs/%1 [L]

This requests
Quote:http://test.catwoman.exite.local/subtitles/search?subs=teststring

gives a $this->uri->uri_string of
Quote:/subtitles/search/subs/teststring

Note: this rewrite has to be placed before the rewrite to index.php, otherwise the first condition will never match.


Routes and GET Query. - El Forum - 08-17-2010

[eluser]pisio[/eluser]
Ok, at the last this must be look :
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 ^subtitles/search$
RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
RewriteRule ^(.*)$ $1/subs/%1 [L]


RewriteRule ^(.*)$ index.php/$1 [L]
?


Routes and GET Query. - El Forum - 08-17-2010

[eluser]Clooner[/eluser]
[quote author="pisio" date="1282062987"]Ok, at the last this must be look :
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 ^subtitles/search$
RewriteCond %{QUERY_STRING} ^subs\=([^&]+)$
RewriteRule ^(.*)$ $1/subs/%1 [L]


RewriteRule ^(.*)$ index.php/$1 [L]
[/quote]
Never thought of this but it is a very clean way to get rid of those get parameters Big Grin Nice