1

ブレッドクラムにはまったく役に立たない、SEO に役立つ、またはユーザーにとって直感的な URL 構造を持つ Web サイトを持っています。のようなものです

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

私は本当にこれを変更したい

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

または非常によく似たもの。このようにして、ブレッドクラムを次の形式で実装できます。

Home > State > City > Company

私が上で説明したように、現在の構造を1つに変換する限り、誰かアイデアはありますか? どう見ても、ウェブサイトの全面的な見直しが必要なようです。ユーザーに次のようなものを表示できるのは素晴らしいことですHome > Florida > Miami > Bob's Haircuts

ありがとう!

4

1 に答える 1

2

ルートを工夫する必要があるだけです: http://ellislab.com/codeigniter/user-guide/general/routing.html

すべてのトラフィックをキャッチして を指すようにルートを設定するとdirectory/listinglistingメソッド内で手動で 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 を変更してから、一覧表示を行うことができます -

したがって、あなたのURLは次のようになります。

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

ルートは次のようになります。

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

次に、メソッドの uri セグメントを更新してlisting、2 番目、3 番目、4 番目、および 5 番目のセグメントと一致させる必要があります。

このようにして、別のコントローラーを呼び出すことができ、カスタムルートによってキャッチされることはありません:

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

アップデート

また、創造性を発揮し、正規表現を使用して、最初の uri セグメントで状態名を持つ URL をキャッチすることもできます。次に、それらをプッシュするdirectory/listingと、他のすべてのコントローラーが引き続き機能directoryし、URL にコントローラーを追加する必要がなくなります。このようなものがうまくいくかもしれません:

// 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
*/
于 2013-01-15T18:08:42.593 に答える