S
S
Sergey Erin2020-11-16 15:38:22
Yii
Sergey Erin, 2020-11-16 15:38:22

How to set a rule for urlManager?

Good day! /frontend/views/site/View files are saved in RU_ch_sitemap.xml, RU_en_sitemap.xml, etc. What rule should be written in urlManager so that when going to mysite.com/RU_ch_sitemap.xml, the corresponding xml file opens?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lykasov, 2020-11-16
@artalexs

If the files are not saved on the web, then you should not give direct access to them unless absolutely necessary. Make a special controller with a method that will give these files
Conditionally:

class DataController {
  public function actionGetSitemap($lang) {
    return file_get_contents(Yii::getAlias('@app/storage') . '/'.$lang);
  }
}

Then the rule can be written something like this:
'/<lang:\w+>_sitemap.xml' => 'data/get-sitemap',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question