Zend使用路由器实现SEO友好或虚荣URL

时间:2012-03-02 09:41:33

标签: zend-framework zend-route zend-router

我有一个简单的电子商务网络应用程序,产品网址如下:

http://www.example.com/product/view/product_id/15

其中“Product”是控制器,“view”是产品控制器中的操作

如何更改此网址以显示为:

http://www.example.com/product/view/product_name/iphone-4S-16-gb

其中product_id“15”是产品表中的主键,product_name的值为“iphone 4s 16 gb”,不带连字符

进行此更改的最简单方法是什么? 真的很感谢你的帮助。 非常感谢。

1 个答案:

答案 0 :(得分:0)

resources.router.routes.view-article.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.view-article.route = "articles/(?!archive)([a-zA-Z\-]+)/(\d+)(?:/(.*))?"
resources.router.routes.view-article.reverse = "articles/%s/%d/%s"
resources.router.routes.view-article.defaults.module = "articles"
resources.router.routes.view-article.defaults.controller = "view"
resources.router.routes.view-article.defaults.action = "view-article"
resources.router.routes.view-article.map.1 = topicSlug
resources.router.routes.view-article.defaults.topicSlug = topicSlug
resources.router.routes.view-article.map.2 = id
resources.router.routes.view-article.defaults.id = 0
resources.router.routes.view-article.map.3 = articleSlug
resources.router.routes.view-article.defaults.articleSlug = articleSlug

http://example.com/articles/circus/616/4-marta-vse-za-ruletkami

这样的链接

http://example.com/products/category/product_id/product_name

编辑1

这是默认路由器插件的设置。从我的博客模块显示为articles,但很容易为商店更新。

部分 - http://example.com/是主持人:) articles/circus/ =>模块和控制器mapeed。

resources.router.routes.view-article.map.1 = topicSlug是一个类别。对于商店。

616/4-marta-vse-za-ruletkami ID和任何slu ..产品描述,例如'iphone-4S-16-gb “

默认值在config中。

另一个例子/{maps2module}/{maps2topicSlug}/{maps2id}/{maps2articleSlug}

相关问题