LoginSignup
1
1

More than 1 year has passed since last update.

【Laravel】ルーティングで定義していないURLにアクセスしたときに自動的にリダイレクトさせる。

Posted at

自分用のメモとして残します。

ルーティングで定義されていないページにアクセスした場合、404エラーを表示するのではなく自動的にリダイレクトさせる方法をメモ。

やり方

Route::fallbackをルーティングに追記する。

routes\web.php
<?php

Route::fallback(function(){ //存在しないURLは自動的にTOPにリダイレクトさせる。
    return redirect(route('home')); 
});

以上です。

1
1
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
1
1