2013-01-15 3 views
1

URL 구조가 빵 부스러기에 유용하지 않거나 SEO에 도움이되거나 사용자에게 직관적 인 웹 사이트가 있습니다. 그것은 정말CodeIgniter에서 유용한 정보가있는 URL 구조를 얻으려면 어떻게해야합니까?

asdf.com/{state}/{city}/{unique_id}/{unique-page-name}/

하거나 매우 유사한 무언가로 변경하고자하는

asdf.com/directory/listing/{unique_id}/{unique-page-name}/

같은입니다. 이 방법은, 내가 사람이 지금까지 제가 위에서 설명한대로 하나에 현재의 구조를 변환하는 등의 어떤 아이디어가 있습니까

Home > State > City > Company

의 형태로 빵 부스러기를 구현할 수있다? 어떤 식 으로든 나는 그것을 보았다, 그것은 웹 사이트의 완전한 개혁을 요구할 것 같다. Home > Florida > Miami > Bob's Haircuts

감사의 말을 사용자에게 표시하는 것이 좋습니다.

+0

경로에 대해 알아 보려면 해결 방법이 있습니다. 사용자 안내서 –

답변

2

당신은 당신의 경로와 창조적 일 필요 것 : http://ellislab.com/codeigniter/user-guide/general/routing.html

당신은 모든 트래픽을 잡아하고 listing 방법 다음 directory/listing로 가리 키도록 경로를 설정할 수 있습니다 - 당신은 수동으로 URL 세그먼트에 액세스 할 수 있습니다 . 예를 들어 : 아마의 경우와 같이

// application/config/routes.php 
$route[':any'] = "directory/listing"; 
    /** 
    you might have to play with this a bit, 
    I'm not sure, but you might need to do something like: 
     $route[':any'] = "directory/listing"; 
     $route[':any/:any'] = "directory/listing"; 
     $route[':any/:any/:any'] = "directory/listing"; 
     $route[':any/:any/:any/:any'] = "directory/listing"; 
    */ 

// application/controllers/directory.php 

function listing() 
{ 
    // docs: http://ellislab.com/codeigniter/user-guide/libraries/uri.html 
    $state = $this->uri->segment(1); 
    $city = $this->uri->segment(2); 
    $unique_id = $this->uri->segment(3); 
    $unique_page_name = $this->uri->segment(4); 

    // then use these as needed 

} 

은 또는, 당신은 다른 컨트롤러와 메소드를 호출 할 수 있어야합니다 - 컨트롤러를 가리 키도록 당신은 URL을 변경할 수 있습니다

을 다음 목록의 물건을 할

asdf.com/directory/{state}/{city}/{unique_id}/{unique-page-name}/ 

및 경로가 될 것입니다 : -

그래서 귀하의 URL이 될 것

$route['directory/:any'] = "directory/listing"; 

그런 다음 listing 방법의 URI 세그먼트를 업데이트하여 2, 3, 4 및 5 번째 세그먼트를 일치시켜야합니다.

이 방법, 당신은 여전히 ​​다른 컨트롤러를 호출 할 수 있고 그것은 사용자 정의 경로에 의해 체포되지 않을 것이다 :

asdf.com/contact/ --> would still access the contact controller and index method 

UPDATE

또한 창의력과에 정규 표현식을 사용할 수 있습니다 첫 번째 URI 세그먼트에있는 주 이름이있는 URL을 찾으십시오. 그런 다음 URL을 directory/listing으로 보내면 다른 모든 컨트롤러가 계속 작동하므로 URL에 directory 컨트롤러를 추가 할 필요가 없습니다. 이 같은 것이 작동 할 수도 있습니다 :

// application/config/routes.php 
$route['REGEX-OF-STATE-NAMES'] = "directory/listing"; 
$route['REGEX-OF-STATE-NAMES/:any'] = "directory/listing"; // if needed 
$route['REGEX-OF-STATE-NAMES/:any/:any'] = "directory/listing"; // if needed 
$route['REGEX-OF-STATE-NAMES/:any/:any/:any'] = "directory/listing"; // if needed 


/** 
REGEX-OF-STATE-NAMES -- here's one of state abbreviations: 
    http://regexlib.com/REDetails.aspx?regexp_id=471 
*/ 
+0

이 솔루션은 완벽하게 작동합니다. 노력에 감사드립니다. :디 –

관련 문제