Answer the question
In order to leave comments, you need to log in
Why is the redirect not working properly?
There is an init method in the controller with two almost identical pieces of code: one makes redirects for links with a plus code, and the second for links with a space code - all this is replaced with a regular plus sign and redirected to a link like site.ru/category+product. But only the redirect for a link with a space code works. For the plus code - 404, and it lands in the controller and even the redirect command works.
public function init()
{
parent::init();
$url = Yii::$app->request->url;
$host = Yii::$app->request->hostInfo;
// redirect pages with %2B - plus
if ((strpos($url, '%2B') !== false)) {
$newUrl = str_replace('%2B', "+", $url);
return $this->redirect($host.$newUrl, 301);
}
// redirect pages with %20 - space
if ((strpos($url, '%20') !== false)) {
$newUrl = str_replace('%20', "+", $url);
return $this->redirect($host.$newUrl, 301);
}
}
Answer the question
In order to leave comments, you need to log in
Where exactly do you insert the plus/space? If after the symbol "?", then everything works. If before - the router simply does not find a suitable controller.
check what you have in $url
when there is a plus. But it seems to me that this should be done in htaccess, but the start of the yii assembly. Why waste resources.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question