yiisoft/yii2 · error · MethodNotAllowedHttpException
Method Not Allowed. This URL can only handle the following r
Error message
Method Not Allowed. This URL can only handle the following request methods: implode(', ', $allowed). What it means
Error "Method Not Allowed. This URL can only handle the following request methods: implode(', ', $allowed)." thrown in yiisoft/yii2.
Source
Thrown at framework/filters/VerbFilter.php:112
*/
public function beforeAction($event)
{
$action = $event->action->id;
if (isset($this->actions[$action])) {
$verbs = $this->actions[$action];
} elseif (isset($this->actions['*'])) {
$verbs = $this->actions['*'];
} else {
return $event->isValid;
}
$verb = Yii::$app->getRequest()->getMethod();
$allowed = array_map('strtoupper', $verbs);
if (!in_array($verb, $allowed)) {
$event->isValid = false;
// https://tools.ietf.org/html/rfc2616#section-14.7
Yii::$app->getResponse()->getHeaders()->set('Allow', implode(', ', $allowed));
throw new MethodNotAllowedHttpException('Method Not Allowed. This URL can only handle the following request methods: ' . implode(', ', $allowed) . '.');
}
return $event->isValid;
}
}
View on GitHub (pinned to 66f00d18a2)
When it happens
Trigger: Thrown at framework/filters/VerbFilter.php:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/34eac28540587eaf.
Report an issue: GitHub.