0

我有一个更改模块网址的请求。

例如,假设网址是 www.example.com/world

我需要网址为 www.example.com/hello/world

我知道在模块配置 xml 中,您可以将节点更改为您喜欢的任何内容(前提是它是唯一的),但不允许添加 /hello/

 <frontend>
    <routers>
        <anexample>
            <use>standard</use>
            <args>
                <module>An_Example</module>
                <frontName>hello/world</frontName>
            </args>
        </anexample>
    </routers>
 </frontend>

有谁知道如何做到这一点?一些示例代码甚至是正确方向的一点将不胜感激!

抱歉,如果这还不够详细,如果需要,我很乐意发布更多我的代码。

提前致谢。

4

5 回答 5

3

您可以将重写添加到 Magento 的 URL 重写管理器中。未测试以下代码。但希望它有所帮助。

Mage::getModel('core/url_rewrite')
->setIsSystem(0)
->setStoreId($storeId)   
->setOptions('RP')  
->setIdPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html')
->setTargetPath($categoryModel->getUrlPath() . '.html')// Put the actual path
->setRequestPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html') // put the path you want to display
->save();
于 2013-09-09T16:08:04.353 回答
0

请参阅 Allan Storm 的以下关于 Magento 重写的文章

http://alanstorm.com/magento_dispatch_rewrites_intro

于 2013-09-09T14:12:13.010 回答
0

在这里,我可以为您提供解决方案的想法,它一定会对您有所帮助

<?xml version="1.0"?>
<config>
  <global>
   <rewrite>
      <some_unique_name_to_identify_this_rewrite>
        <from><![CDATA[#^/from_this/#]]></from>
        <to>/to_this/</to>
      </some_unique_name_to_identify_this_rewrite>
   </rewrite>
</global>
</config>

如果你想用管理员功能重写 url,你可以抛出这个链接

您想要实现的目标也可以通过自定义 URL 重写来完成。例如:

request path: hello/world

target path: 'world'

通过这种方式,您将成为系统重写的起点。

希望这对你有帮助

于 2013-09-09T15:17:51.390 回答
0

最后这很简单。而不是去为它创建一个重写的麻烦,我只是将我的名字改为“你好”,然后创建了一个名为“worldController”的控制器

然后在我的 indexController 中,我只是将重定向到 */world

于 2013-09-12T16:08:44.230 回答
0

访问自定义模块控制器路径作为自定义 HTML Url 链接

http://domain.com/index.php/customwallpaper/index/create/

将被改写为

http://domain.com/index.php/fotomural-personalizado.html

在core_url_rewrite表中插入以下数据以进行 url 重写

Mage::getModel('core/url_rewrite')
    ->setStoreId(1)   
    ->setIdPath('customwallpaper')
    ->setRequestPath('fotomural-personalizado.html')
    ->setTargetPath('customwallpaper/index/create') // Put the actual Controller path
    ->setIsSystem(1)
    ->save();

-或者-

运行下面的sql查询

INSERT INTO `core_url_rewrite` 
(`url_rewrite_id`, `store_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`, `category_id`, `product_id`) 
VALUES ('7', '1', 'customwallpaper', 'fotomural-personalizado.html', 'customwallpaper/index/create', '1', NULL, NULL, NULL, NULL);
于 2016-08-23T11:38:32.557 回答