M
M
MyQuestion2022-03-13 14:54:14
Yii
MyQuestion, 2022-03-13 14:54:14

Yii2: how to make a 301 redirect on a website without .htaccess?

Good afternoon!

For some reason, .htaccess is disabled on the site, how to make a 301 redirect from one page to another, in yii2?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MyQuestion, 2022-03-13
@MyQuestion

If anyone is interested, I solved it like this:

if ($_SERVER['REQUEST_URI']=='/path/to/page') {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: https://site/path/to/page'");
    exit();
  }

if ($_SERVER['REQUEST_URI']=='/path/to/page') {
    Yii::$app->response->redirect('/path/to/page', 301)->send();
    Yii::$app->end();
    return;
  }

M
Michael, 2022-03-13
@Akela_wolf

https://www.yiiframework.com/doc/api/2.0/yii-web-c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question