【发布时间】:2015-12-30 15:51:50
【问题描述】:
我正在尝试制定自定义 URL 要求。我们是一个基于产品的网站,每个产品的 url 就像
https://www.domainname.com/product/index/id/product_id
现在我希望网址是用户友好的,类似这样..
https://www.domainname.com/productcustomurl
为了实现这一点,我在表product 中创建了一个名为custom_url 的字段,其中customurl 将由产品创建者在产品创建期间存储。为此,我在 params.php 中创建了一个规则,如下所示:
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<id:(.*?)>' => 'product/index' //this rule
假设每当有人在参数id 中使用productcustomurl 命中https://www.domainname.com/productcustomurl 时,这将重定向用户,这工作正常,但问题是这会将所有内容重定向到product/index,覆盖所有其他路由,例如site/index 或 site/about 等等等等,这是一个问题。我希望他们工作。如何在不影响网站正常路由的情况下实现??
请帮忙。
【问题讨论】:
标签: php yii url-rewriting url-routing params