2016-08-16 2 views
0

В моем веб-страницу входа поиска Я использую получить метод и URL-то вроде этого www.example.com/search?city=example&service=example2, но я хочу URL, как этот www.example.com/search/example/example2; как я могу конвертировать?CodeIgniter Получ и SEO дружественных URL-

Возможно, есть какое-то другое решение для получения данных из входов html и получения дружественного URL-адреса?

+1

Посмотрите на это: https://www.codeigniter.com/userguide3/general/routing.html –

+0

GET откуда ?? form submit или '' ?? –

ответ

0

В файле routes.php внутри папки конфигурации:

$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.

Теперь внутри 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> 
 
    
 
    
 
}

2

Я думаю, что это помогает вам, а также SEO. Пожалуйста, напишите следующие Uri правила: application/config/routes.php

$route['search-(:any)-(:any).html'] = 'search?city=$1&service=$2'; 

его переписать свой адрес из www.example.com/search?city=example&service=example2 в www.example.com/search-example-example2.html

0

Я вижу другие публикации о маршрутизации, да я могу сделать как то, но я думаю, что первый мне нужно решить проблема с html submit action, потому что когда я нажимаю кнопку, она автоматически перенаправляет на какой-то стандартный URL-адрес search?city=example&service=example2, но, как я уже сказал, мне нужен другой формат. Итак, как я могу решить эту проблему?

Моя форма действия

<form method="get" action="http://example.com/search"> 
Смежные вопросы