title: Yii2: how to redirect old URLs with 301?
body: <p>I have some URLs from the old version of my site that I want to redirect to their new ones in Yii2 due to SEO purposes, eg. <code>/about-us.php</code> to <code>/about</code>. How do I do that?</p>
  
  <p>I can't use <code>.htaccess</code>, and I can't use <code>urlManager</code> rules because HTTP response status 301 needs to be set.</p>
  
  <p>I tried the following in a bootstrap class but even though the code executes I still just get a 404 when going to the old URL:</p>
  
  <pre class="lang-php prettyprint-override"><code>if (preg_match("|^/about.php|", $_SERVER['REQUEST_URI'])) {
      Yii::$app-&gt;response-&gt;redirect('/about', 301)-&gt;send();
      return;
  }
  </code></pre>