LoginSignup
2

More than 3 years have passed since last update.

baserCMSで短いURLでブログ記事にアクセスする

Last updated at Posted at 2018-12-05

こんにちは。『baserCMS Advent Calendar 2018』5日目担当の ryuring です。
あまり時間がないので小ネタだけ。

baserCMSのブログ記事のURLは、WordPressの初期状態に似て少し長いんですよね。

こんな感じ。

http://localhost/news/archives/1

たまにSEOうるさい人が、URL短くしろよとか言いますよね。
なのでそれを叶えてあげるためにこんな感じにする方法を書きます。

http://localhost/1

プラグインとして作りましょう。

例えば、ShortUrl プラグインとして作る場合。
まず、ルーティング設定用のファイル app/Plugin/ShortUrl/Config/routes.php を作ります。

// routes.php
Router::connect('/:no',
    ['plugin' => 'blog', 'controller' => 'blog', 'action' => 'archives', 'entityId' => 1],
    ['pass' => ['no'], ['no' => '[0-9]+']]
);

entityId は、ブログコンテンツIDになります。管理画面で調べましょう。

あとは、管理画面で、プラグインを有効化すれば完了です。

これは baserCMSの特別な機能ではなく、CakePHPの標準機能なんですね。

Cakeすげえ。viva Cake!
と言って、Laravelに追い抜かれてしまった Cake の後押しをしてみる。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
2