Magento 模块的 URL 重写

发布于 2024-10-13 05:49:20 字数 720 浏览 9 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼眸 2024-10-20 05:49:20

我自己没有这样做,只是在这里阅读了相关内容,但是这里...

在您的 config.xml 文件中:

<config>
    <global>
        <rewrite>
            <article_article_archives>
                <from><![CDATA[#^/article/archives/#]]></from>
                <to><![CDATA[/article/article/archives/]]></to>
            </article_article_archives>
        </rewrite>
    </global>
</config>

节点 的格式并不严格,它只需要与其他重写不同即可。

I've not done this myself, only read about it here, but here goes...

In you config.xml file:

<config>
    <global>
        <rewrite>
            <article_article_archives>
                <from><![CDATA[#^/article/archives/#]]></from>
                <to><![CDATA[/article/article/archives/]]></to>
            </article_article_archives>
        </rewrite>
    </global>
</config>

The node <article_article_archives> isn't strictly formed, it only needs to be unique from other rewrites.

夜巴黎 2024-10-20 05:49:20

.htaccess 中类似的东西

RewriteEngine On
RewriteRule ^(article/)* article/ [L]

可能会删除重复项,但我不会选择它

重复项的更一般情况:

RewriteEngine On
RewriteRule ^([^/]+/)* $1 [L]

Something like this in .htaccess

RewriteEngine On
RewriteRule ^(article/)* article/ [L]

May remove duplicates, but I wouldn't opt for it

A more general case for duplicates:

RewriteEngine On
RewriteRule ^([^/]+/)* $1 [L]
清醇 2024-10-20 05:49:20

好吧,如果您的模块中有多个控制器,您可能不会接受此选项,但这是一个有效的解决方案,无需在 .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/.

守望孤独 2024-10-20 05:49:20

好吧,如果您有多个,您可能不会接受此选项
模块中的控制器,但它是一个有效的解决方案,无需
在 .htaccess 等中创建额外的重写规则。这是可能的
使用 IndexController.php 设置“文章”模块
ArticleController.php 的。然后你可以使用以下命令访问页面
[http://]mydemostore/article/archives/01/2011....在哪里
archivesAction() 是 IndexController.php 中的一个方法。马根托
自动将 IndexController.php 映射到 /yourmod/index/ 或只是
简单地/yourmod/。


不幸的是,mydemostore/article/archives/01/2011不会引用IndexController->archivesAction,但是
archivesController->01Action 这将导致错误,因为 PHP 中的方法/函数只能以下划线或字母开头。

但是,以下网址将引用提到的控制器操作对:

  • mydemostore/article/index/archives/
  • mydemostore/article//archives/

关于原始问题,在 Magento 中保存编程 URL 重写将是最佳实践,但不一定
最实用或最快实施的;当然,Apache 指令(例如 .htaccess 或站点配置文件)将是最快的,但不是
最遵守最佳实践。

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/.


Unfortunately, mydemostore/article/archives/01/2011 will NOT refer to the IndexController->archivesAction, but
archivesController->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:

  • mydemostore/article/index/archives/
  • mydemostore/article//archives/

Regarding the original question, saving programmatic URL rewrites within Magento would be the best practice, but not necessarily
the 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文