LoginSignup
9
2

More than 5 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 の後押しをしてみる。

9
2
0

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
  3. You can use dark theme
What you can do with signing up
9
2