Rewrite dynamic Magento URL

最后都变了- 提交于 2019-12-23 05:10:51

问题


I have a Magento v1.4.1.1 installation on Nginx web server. I'm trying to rewrite the following dynamic URL:

#5028 is the dynamic id passed in the URL
$baseUrl/design/index/index/design_id/5028

To:

$baseUrl/my/design/5028

I have used the Magento's "URL Rewrite Management" to rewrite static URLs, without a problem. But it seems I cannot use dynamic parameters.

I've also tried to do the following on Nginx configuration inside my server{} location

rewrite ^/my/designs/([0-9]+)$ /design/index/index/design_id/$1 last;

But it's not getting catch, I keep getting 404 errors if I try to access http://mysite.com/my/design/5028

Another rule right next to this one works perfectly

rewrite ^(/fb)/design/([0-9]+)$ $1/landing_no_contest.php?design_id=$2? last;

Thanks for any help.


回答1:


Yes, Magento's "URL Rewrite Managment" does not support dynamic links, afaik.

You could programmatically add static rewrites per design_id to it, though:

$iStoreId = 1;
$sOptions = 'RP'; // 'RP' for a 301, or 'R' for a 302
$aDesignId = array(5026, 5027, 5028);

foreach ($aDesignId as $iDesignId) {
    Mage::getModel('core/url_rewrite')
        ->setStoreId($iStoreId)
        ->setCategoryId(null)
        ->setProductId(null)
        ->setIdPath(str_replace('0.', '', str_replace(' ', '_', microtime())))
        ->setRequestPath('design/index/index/design_id/' . $iDesignId)
        ->setTargetPath('my/design/' . $iDesignId)
        ->setIsSystem(0)
        ->setOptions($sOptions)
        ->save();
}


来源:https://stackoverflow.com/questions/11956200/rewrite-dynamic-magento-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!