Magento 模块的 URL 重写
我在 Magento 中创建了一个新模块并将其命名为“文章”。它有两个前端控制器索引和文章。
在文章控制器中,我有一个名为“档案”的操作,用于根据档案列出前端/网站上的文章。除了网址之外一切都很好。
现在的工作网址是:[http://]mydemostore/article/article/archives/01/2011
我真正需要的是 http://mydemostore/article/archives/01/2011
我不想有额外的“文章”(控制器名称)
我知道,因为我的模块名称和控制器名称是相同的我我明白了。如果我将我的操作放在索引控制器中,我就可以完成此操作。但它不起作用。
所以我现在需要的是我不想将我的操作从“文章”移动到“索引”控制器,而是我只想
从
[http://]mydemostore/article/article/archives/01/2011 更改为
到
[http://]mydemostore/article/archives/01/2011
使用 Zend 路由或基本 PHP URL 重写 .htaccess 文件
。请帮助我如何通过使用这两种方式或同时使用这两种方式来完成此操作。
非常感谢您检查我的问题!
I have created a New Module in Magento and named it as "article". It has two Front end controllers index and article.
And in the article controller i have an action called "archives" to list the articles on the front end / website based on the archives. Everything is fine except the URL.
The Working URL right now is : [http://]mydemostore/article/article/archives/01/2011
What i actually need is http://mydemostore/article/archives/01/2011
I don't want to have an extra "article" (the controller name)
I know since my module name and controller name are same i am getting this. If i would have placed my actions inside the indexcontroller, i would have got this done. But it was not working.
So what i need right now is I don't want to move my actions from "article" to "index" controllers rather i just want to change
from
[http://]mydemostore/article/article/archives/01/2011 to
to
[http://]mydemostore/article/archives/01/2011
using Zend routing or basic PHP URL rewriting on .htaccess file.
Kindly help me how to get this done by using either of these two ways or both the ways.
Thanks a lot in advance for checking with my question !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己没有这样做,只是在这里阅读了相关内容,但是这里...
在您的 config.xml 文件中:
节点
的格式并不严格,它只需要与其他重写不同即可。I've not done this myself, only read about it here, but here goes...
In you config.xml file:
The node
<article_article_archives>
isn't strictly formed, it only needs to be unique from other rewrites..htaccess 中类似的东西
可能会删除重复项,但我不会选择它
重复项的更一般情况:
Something like this in .htaccess
May remove duplicates, but I wouldn't opt for it
A more general case for duplicates:
好吧,如果您的模块中有多个控制器,您可能不会接受此选项,但这是一个有效的解决方案,无需在 .htaccess 等中创建额外的重写规则。可以使用IndexController.php 而不是 ArticleController.php。然后您可以使用 [http://]mydemostore/article/archives/01/2011.... 访问页面,其中 archivesAction() 是 IndexController.php 中的一个方法。 Magento 自动将 IndexController.php 映射到 /yourmod/index/ 或简单地 /yourmod/。
Well, you might not be open to this option if you have several controllers in your module, but it is a valid solution without creating extra rewrite rules in your .htaccess, etc. It is possible to set your "articles" module up with an IndexController.php instead of an ArticleController.php. Then you could access the pages with [http://]mydemostore/article/archives/01/2011.... where archivesAction() is a method in the IndexController.php. Magento automatically maps the IndexController.php to /yourmod/index/ or just simply /yourmod/.
不幸的是,
mydemostore/article/archives/01/2011
不会引用IndexController->archivesAction
,但是archivesController->01Action
这将导致错误,因为 PHP 中的方法/函数只能以下划线或字母开头。但是,以下网址将引用提到的控制器操作对:
关于原始问题,在
Magento
中保存编程 URL 重写将是最佳实践,但不一定最实用或最快实施的;当然,Apache 指令(例如 .htaccess 或站点配置文件)将是最快的,但不是
最遵守最佳实践。
Unfortunately,
mydemostore/article/archives/01/2011
will NOT refer to theIndexController->archivesAction
, butarchivesController->01Action
which will result in an error since method/function in PHP can only start with an underscore or a letter.However, the following urls will refer to the controller-action pair mentioned:
Regarding the original question, saving programmatic URL rewrites within
Magento
would be the best practice, but not necessarilythe most practical or quickest to implement; of course, Apache directives (e.g. .htaccess or site conf files) will be the quickest but not
most observant of best practices.