【问题标题】:How to rewrite custom module url including id with any custom url in Magento如何用 Magento 中的任何自定义 url 重写自定义模块 url,包括 id
【发布时间】:2016-04-12 18:18:10
【问题描述】:

我在 Magento 中安装了免费扩展的 storelocator。但是如果单击 View Details 按钮,它会以 storelocator/index/view/id/1/ 打开。出于 SEO 目的,需要使用 hearing-aid-center-in-new-york 或 hearing-aid-center-in-Chicago 打开。在这里,hearing-aid-center-in- 很常见,new-york, chikago 将变得充满活力。那么,对于这个需求,如何重写这个url。以及我应该在哪里为上述要求编写重写代码。在本网站https://magento.stackexchange.com/questions/73369/custom-url-for-magento-extension 的帮助下,通过使用 Magento 事件“controller_front_init_routers”创建观察者,我尝试了很多使用 id 1 作为静态方式的方法。它保存在 core_url_rewrite 中,它显示在“URL 重写管理”部分,它也重定向,但重定向 404 Not Found 页面。我不明白为什么它重定向 404 Not Found 页面以及如何实现它以及如何获取 id以overserver动态方式的storelocator。

除此之外,我还需要覆盖客户帐户 url 和销售订单历史记录 url。 我不知道如何用 /my-account/order-history 而不是 /sales/order/history/ 以及 重写客户帐户网址/my-account/dashboard 而不是 /customer/account/。我不明白如何为友好的 SEO 目的实现这些要求。任何帮助,谢谢。

【问题讨论】:

    标签: php url-rewriting magento-1.9 custom-url


    【解决方案1】:

    您需要使用依赖于它的新模块来扩展 Store 定位器。有很多关于如何做到这一点的帖子。该模块需要为 URL Key 添加一个附加属性,例如纽约。它还需要一个扩展Storelocator_IndexController 的新控制器。该控制器将处理所有对 Store 的请求。它将通过 URL Key 而不是 ID 查找 Store。一旦有了这个,它将像以前一样继续使用继承代码。当然,您必须覆盖和更新所有 Url 才能使用该密钥。

    最后,您需要在config.xml 中设置一个重写规则,例如:

    <config> <global> <rewrite> <mymodule_storelocatoroverides_view> <from><![CDATA[#^\/hearing\-aid\-center\-in\-([a-z\-]+)[\/]?$#]]></from> <to><![CDATA[mymodule/storelocatoroverides/view/id/1/]]></to> <complete>1</complete> </mymodule_storelocatoroverides_view> </rewrite> </global> </config>

    或者

    作为一种快速解决方案,但绝不是最佳解决方案:

    如果您的商店数量有限,那么您可以在模块 config.xml 中简单地添加重写规则(创建一个简单的插件),例如纽约(假设其 ID 为 1):

    <config> <global> <rewrite> <mymodule_storelocatoroverides_newyork> <from><![CDATA[#^\/hearing\-aid\-center\-in\-new\-york[\/]?$#]]></from> <to><![CDATA[storelocator/index/view/id/1/]]></to> <complete>1</complete> </mymodule_storelocatoroverides_newyork> </rewrite> </global> </config>

    您必须再次覆盖 Url 输出。

    对于客户网址,您可以再次使用相同的方法。因此,将 Rewrites 添加到 config.xml 并替换 Url 链接以使用您的新重写。同样,您可能必须覆盖核心代码才能更改重定向。

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 2012-08-29
      • 2015-02-28
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      相关资源
      最近更新 更多