0
0

パス部分に%2F(/)スラッシュは使えないのでクエリパラメータでパラメータを指定した

Last updated at Posted at 2024-06-28

下記のようなURLでパラメータをパスで受け取ろうとして、404になった。

https://example.com/path/hoge%2Ffuga/
route.php
Route::get('/path/{param}', 'HogeController@index');

パスでパラメータを受け取ろうとしていた。が/(スラッシュ)は予約文字ということでパスには使えないことが判明。
下記がエビデンス。
https://www.ietf.org/rfc/rfc2396.txt#:~:text=2.2.%20Reserved%20Characters

代わりに、

route.php
Route::get('/', 'HogeController@index');
HogeController.php
$request->query('url');

で受け取るようにした。
下記のようなURLで正常に遷移してくれるようになりました。

https://example.com/path/?url=hoge/fuga

地味に時間を使ったので備忘録として残しておきます。

他にも予約文字があり、パスには使用できないので覚えておきたい。。。。

「; / ? : @ & = + $ ,」

ご一読ありがとうございました。

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