Reputation: 103
In my web page search input I am using the get method, and the URL is something like this www.example.com/search?city=example&service=example2
, but I want a URL like this www.example.com/search/example/example2
; how can I convert?
Or maybe there is some other solution to get the data from html inputs and get a friendly URL?
Upvotes: 0
Views: 583
Reputation: 103
I see others posting about routing, yes i can do like what, but i think first i need to solve problem with html submit action, because when i press the button its auto redirect to what standart format url search?city=example&service=example2
, but like i say i need other format. So how i can solve this problem?
My form action
<form method="get" action="http://example.com/search">
Upvotes: 0
Reputation: 1609
I think its help you and also SEO.
Please write following uri rules in : application/config/routes.php
$route['search-(:any)-(:any).html'] = 'search?city=$1&service=$2';
its rewrite your url from www.example.com/search?city=example&service=example2
to www.example.com/search-example-example2.html
Upvotes: 1
Reputation: 1171
In your routes.php file inside the config folder:
$route['search/(:any)'] = 'search/searchFunction'; //You will now need to have a searchFunction() inside the controller search. Or you can just have 'search' and handle the code below inside the index() function.
Now, inside your searchFunction:
function searchFunction()
{
$city = (isset($this->uri->segment(2))) ? $this->uri->segment(2) : null; //if you have www.example.com/search/example
$service = (isset($this->uri->segment(3))) ? $this->uri->segment(3) : null; //if you have www.example.com/search/example/example2
//General Pattern is: www.example.com/uri-segment-1/uri-segment-2/uri-segment-3.....and so on.
// Now when you are querying, if($city) then 'WHERE city = $city' and so on.
//Also, in the link that was earlier triggering 'www.example.com/search?city=example&service=example2'
//like <a href='www.example.com/search?city=example&service=example2'>Link</a>
//Now have it as:
// <a href='www.example.com/search/example/example2'>Link</a>
}
Upvotes: 0