title: How to set correctly Page routing of a Site?
body: <p>I’ve troubling about my site’s routing. All of my SEO meta elements are implemented via Metadata’s section of my CMS. One of the most important entry, named by Page routing, does work correctly. I’m going to create Meta tags for a specific page. Once I put the desired link as input in the entry “page routing” to implement those Meta tags, it does not work. For example, consider the following hierarchy to show the exact issue.</p>
  
  <p><strong>Home -> Course -> Course 1 -> topic 1 , topic 2 , … -></strong> </p>
  
  <p>When I choose, say topic 1, and want to create Metas for it, the final Tags are implemented are the ones for Course section! In other words, the internal links of the Course section of my site do not accept Tags. </p>
  
  <p>I'm new to programming and couldn't find who solve this problem.</p>
  
  <p>some section of my Layout is as follows:</p>
  
  <pre><code>&lt;link rel="canonical" href="https://physexams.com/&lt;?=Yii::$app- &gt;controller-&gt;id."/". Yii::$app-&gt;controller-&gt;action-&gt;id?&gt;" /&gt;
  
  &lt;link rel="publisher" href="&lt;?=$metadata-&gt;publisher?&gt;" /&gt;
  
  &lt;title&gt;&lt;?= Html::encode($metadata-&gt;title) ?&gt;&lt;/title&gt;
  
  &lt;meta charset="&lt;?= Yii::$app-&gt;charset ?&gt;"&gt;
  
  &lt;meta name="description" content="&lt;?=$metadata-&gt;meta_description?&gt;"/&gt;
  
  </code></pre>
  
  <p>and part of Controller and its action is:</p>
  
  <pre><code>class CoursesController extends Controller
  {
  
      /**
       * @inheritdoc
       */
      public function actions()
      {
          return [
              'error' =&gt; [
                  'class' =&gt; 'yii\web\ErrorAction',
              ],
              'captcha' =&gt; [
                  'class' =&gt; 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
      /**
       * Displays homepage.
       *
       * @return mixed
       */
      public function actionIndex( $id = 0   )
      {
          $coursesP = [] ;
          if ( $id != 0 )
          {
              $coursesP = Courses::find()-&gt;where(['id'=&gt; $id , 'itsok' =&gt; "yes"])-&gt;with('lessons')-&gt;one();
  
              if ( empty($coursesP) )
              {
                  $this-&gt;redirect(Url::to(['courses']));
              }else {
  
                  $courses = Lessons::find()-&gt;where(['course_id' =&gt; $coursesP-&gt;id, 'itsok' =&gt; "yes"])-&gt;all();
              }
          }
          else {
  
              $courses = Courses::find()-&gt;where(['itsok' =&gt; "yes"])-&gt;with('lessons')-&gt;all();
  
          }
  
          return $this-&gt;render('index' , [
              'courses' =&gt; $courses ,
              'id' =&gt; $id ,
              'parent' =&gt; $coursesP
          ]);
      }
      public function actionInternal( $id  = 0 )
      {
  
  
  
          if ( $id == NULL)
          {
              return $this-&gt;redirect(Url::to(['courses/index']));
          }
  
          $lesson = Lessons::find()-&gt;where(['itsok' =&gt; 'yes' , 'id' =&gt; $id])-&gt;with(['course' , 'lessonElements'])-&gt;one();
          $otherLessons = Lessons::find()-&gt;where(['course_id' =&gt; $lesson-&gt;course_id  , 'itsok' =&gt; 'yes'])-&gt;all();
  
          if ( empty( $lesson-&gt;id) )
          {
              return $this-&gt;redirect(Url::to(['courses/index']));
          }
  
          return $this-&gt;render('internal' , [
              'lesson' =&gt; $lesson ,
  
              'otherLessons' =&gt; $otherLessons
  
          ]);
      }
  
  }
  </code></pre>
  
  <p>The UrlManager config file is</p>
  
  <pre><code>&lt;?php
  
  $params = array_merge(
      require(__DIR__ . '/../../common/config/params.php'),
      require(__DIR__ . '/../../common/config/params-local.php'),
      require(__DIR__ . '/params.php'),
      require(__DIR__ . '/params-local.php')
  );
  
  
  use \yii\web\Request;
  $baseUrl = str_replace('/frontend/web', '', (new Request)-&gt;getBaseUrl());
  
  
  
  return [
      'id' =&gt; 'app-frontend',
      'basePath' =&gt; dirname(__DIR__),
      'bootstrap' =&gt; ['log', 'thumbnail'],
      'controllerNamespace' =&gt; 'frontend\controllers',
      //'defaultRoute' =&gt; '/site/index',
  
      'components' =&gt; [
          'request' =&gt; [
              'baseUrl' =&gt; $baseUrl,
          ],
          'urlManager' =&gt; [
              'baseUrl' =&gt; $baseUrl,
              'class' =&gt; 'yii\web\UrlManager',
  
              'enablePrettyUrl' =&gt; true,
              'showScriptName' =&gt; false,
              'enableStrictParsing' =&gt; false,
              'rules' =&gt; [
                  'home' =&gt; 'site/index' ,
                  '/' =&gt; 'site/index', 
                  'frontend/web' =&gt; 'site/index',
                  'index' =&gt; 'site/index',
                  'site' =&gt; 'site/index',
                  'site/login' =&gt; 'site/login' ,
                  'site/contact' =&gt; 'site/contact' ,
                  'site/about' =&gt; 'site/about' ,
                  'site/faq' =&gt; 'site/faq' ,
                  'profile/logout' =&gt; 'profile/logout',
                  'profile' =&gt; 'profile/index',
                  'lesson/&lt;lesson:\w+&gt;/&lt;id:\d+&gt;' =&gt; 'courses/internal',
                  'lesson' =&gt; 'courses/internal',
  
                  'course/&lt;cat:\w+&gt;/&lt;id:\d+&gt;' =&gt; 'courses/index',
                  'courses' =&gt; 'courses/index',
  
                  'exam/&lt;cat:\w+&gt;/&lt;id:\d+&gt;' =&gt; 'exam/internal',
                  'exam' =&gt; 'exam/index',
  
                  'ticket' =&gt; 'ticket/index',
  
  
  
                  'flashcard/&lt;cat:\w+&gt;/&lt;id:\d+&gt;' =&gt; 'blog/internal',
                  'blog/&lt;cat:\w+&gt;/&lt;id:\d+&gt;' =&gt; 'blog/cat',
                  'blog' =&gt; 'blog/index',
  
                  '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;' =&gt; '&lt;controller&gt;/&lt;action&gt;',
  
  
              ],
              ],
          'user' =&gt; [
              'identityClass' =&gt; 'common\models\User',
              'enableAutoLogin' =&gt; true,
          ],
          'log' =&gt; [
              'traceLevel' =&gt; YII_DEBUG ? 3 : 0,
              'targets' =&gt; [
                  [
                      'class' =&gt; 'yii\log\FileTarget',
                      'levels' =&gt; ['error', 'warning'],
                  ],
              ],
          ],
          'errorHandler' =&gt; [
              'errorAction' =&gt; 'site/error',
          ],
  
          'thumbnail' =&gt; [
              'class' =&gt; 'himiklab\thumbnail\EasyThumbnail',
              'cacheAlias' =&gt; 'assets/gallery_thumbnails',
          ],
          'assetManager' =&gt; [
              'class' =&gt; 'yii\web\AssetManager',
              'bundles' =&gt; [
                          'yii\web\JqueryAsset' =&gt; [
                              'js' =&gt; [
                                  'jquery.min.js'
                              ]
                          ],
  
                          'yii\bootstrap\BootstrapAsset' =&gt; [
                              'css' =&gt; [
                                 'css/bootstrap.min.css',
                              ]
                          ],
  
              ],
          ],
      ],
      'params' =&gt; $params,
  ];
  
  </code></pre>
  
  <p>I want the Routing element works for every link which I put exactly in the Metadata section of my CMS</p>