【问题标题】:Zend Implementing SEO friendly or vanity URLs with routerZend 使用路由器实现 SEO 友好或虚荣 URL
【发布时间】:2012-03-20 19:41:43
【问题描述】:

我有一个简单的电子商务 Web 应用程序,其产品 URL 如下:

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

其中“产品”是控制器,“视图”是产品控制器中的操作

如何更改此 URL 以显示为:

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

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

对我来说进行此更改的最简单方法是什么。 非常感谢您的帮助。 非常感谢。

【问题讨论】:

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


    【解决方案1】:
    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,但可以轻松更新商店。

    parts - http://example.com/ 是主机 :) articles/circus/ => 模块和控制器映射。

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

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

    默认值在配置中。

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

    【讨论】:

    • 也许有点解释?
    • 谢谢。对我而言足够了。我得到了它。 :-D
    • 感谢 SMka 的意见,但我对这个话题很陌生,我无法理解它。有什么简单的教程可以读到吗
    • ZF 没有什么简单的 :)))) 但请阅读文档。有很多例子。 framework.zend.com/manual/en/zend.controller.router.html
    猜你喜欢
    • 1970-01-01
    • 2012-01-17
    • 2012-10-06
    • 2011-12-24
    • 2011-04-06
    • 2012-10-24
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    相关资源
    最近更新 更多