当前位置:Gxlcms > PHP教程 > Yii2框架URL伪静态如何配置?

Yii2框架URL伪静态如何配置?

时间:2021-07-01 10:21:17 帮助过:5人阅读

Yii2 框架如何将 www.test.com/product.html?id=5252 这样的 配置成www.test.com/product-5252.html

回复内容:

Yii2 框架如何将 www.test.com/product.html?id=5252 这样的 配置成www.test.com/product-5252.html

可以尝试在配置文件里设置类似以下这种形式

  1. <code><!--?php
  2. return [
  3. ...
  4. 'components' =--> [
  5. ...
  6. 'urlManager' => [
  7. 'enablePrettyUrl' => true,
  8. 'showScriptName' => true,
  9. 'suffix' => '.html',
  10. 'rules' => [
  11. 'product-<id:\d+>' => 'product/view',
  12. ],
  13. ],
  14. ],
  15. ...
  16. ];</id:\d+></code>

人气教程排行