Magento – How to get target url for entity before rewrite

overridesurl

Suppose I want to open contact page: {website}/contact, this page is also represented like {website}cms/page/view/id/12.

Is it possible to get somehow to get this url ({website}cms/page/view/id/12)? I'm trying to get it from request object, but without success.

UPD

Maybe I was to abstract. When I'm on some page: product, blog, cms, I need some unique value which will identify this page when I'll open it. Every time. I thought it can be such kind of url.

Best Answer

If I understand your post correctly you are looking to uniquely identify any given requested resource, not just CMS pages, right?
As you've found out, in most cases that works fine, except that for the CMS pages where the page_id param isn't added to the request path info.

The following should suffice in most cases, though you might want to customize it for layered navigation query arguments and such.

public function getRequestIdentifier()
{
    $req = $this->getRequest();
    $params = array('page_id', 'id', 'category', 'p', 'limit', 'order');
    $parts = array(
        $req->getModuleName(), $req->getControllerName(), $req->getActionName()
    );
    foreach ($params as $p) {
        $value = $req->getParam($p, false);
        if (false !== $value) {
            $parts[] = $p;
            $parts[] = $value;
        }
    }
    return implode('/', $parts);
}
Related Topic