Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:33:32+00:00 2026-05-27T18:33:32+00:00

I am trying to load a rewrite rule based on a product’s URL path.

  • 0

I am trying to load a rewrite rule based on a product’s URL path.

I am using the loadByRequestPath() method in Mage_Core_Model_Url_Rewrite to accomplish this. However, no matter what I supply this method I get the following result (Check comment in code):

public function loadByRequestPath($path)
{ 
    Zend_Debug::dump($path); // returns the path to my module
    $this->setId(null);
    $this->_getResource()->loadByRequestPath($this, $path);
    $this->_afterLoad();
    $this->setOrigData();
    $this->_hasDataChanges = false;
    return $this;
}

Here is my module code:

$productRewrite = Mage::getModel('core/url_rewrite') ->loadByRequestPath($product->getUrlPath());

Oddly, I get this back:

Array ( [0] => rewrites/getProductRewrites
        [1] => rewrites/getProductRewrites/ )
Array ( [0] => 01003-product-name )

So loadByRequestPath() is getting called twice for whatever reason. $productRewrite still returns an empty object.

I have verified that $product->getUrlPath() returns the correct path. (As seen in the second array)

I am on Magento 1.6.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:33:33+00:00Added an answer on May 27, 2026 at 6:33 pm

    Your question is still a little unclear, so this answer might not address the specific problem you’re seeing.

    Magento’s core team hasn’t done a great job of communicating these sorts of things over the years, but loadByRequestPath is one of those methods that’s best thought of as a “private api”. Not in the OOP sense, but in the “this is a method used to implement core system functionality, and probably won’t work like you think it should work, so use at your own risk”.

    The PHP code you’re trying to use

    $productRewrite = Mage::getModel('core/url_rewrite') ->loadByRequestPath($product->getUrlPath());
    

    won’t work with a default installation of Magento because the rewrite object doesn’t have a store ID set. Trying something like this should work. (assuming the sample data, with an installed store object that has an ID of “1” and that the product in question exists in that store)

    $productRewrite = Mage::getModel('core/url_rewrite');
    $productRewrite->setStoreId(1);
    $productRewrite->loadByRequestPath($product->getUrlPath());
    

    The loadByRequestPath method assumes that a rewrite already has a store ID set, as it’s part of Magento’s larger dispatching process. (self-link to article describing the role of rewrites in Magento’s routing system)

    All that said, the problem you’re describing is somewhat confusing. You say that

    Zend_Debug::dump($path);
    

    returns

    an array that contains the path to my module

    While I’m sure you know what the phrase “path to my module” means, it’s a meaningless term in the larger magento universe. Being more specific about the literal value will help people understand what you mean.

    Additionally, you also say

    I have verified that $product->getUrlPath() returns the correct path.

    but you’re not clear on the value of “the correct path”.

    My guess would be the path you’re seeing in Zend_Debug::dump is the call that’s coming through as a part of the standard dispatch and not your later call using $product->getUrlPath(). However, the lack of clarity in your question makes that hard to tell.

    If setting the store ID doesn’t get you what you want, update your question with a full explanation of how you’re running your code, and what you see displayed. With that information more people will be able to help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load spring beans using XmlWebApplicationContext setConfigLocations method. However, I keep getting
I'm trying to make user friendly URL using mode rewrite. My problem is, that
I'm trying to load fragments of XHTML markup using jQuery's $.fn.load function, but it
I'm using jQuery 1.5.2 trying to dynamically load a div from one source into
I'm trying to change my URL for http://www.tomttb.com/school/index.php?page=p/logbook/my.php To http://www.tomttb.com/school/logbook/my I now have this:
I'm trying to figure something out. This is the code I'm using to hide
Im trying to load a flash movie using swfobject which i have been successful
I'm trying to rewrite some code using the sqldf library in R, which should
I'm trying to rewrite this as a for loop; my attempt below failed. Any
I have a problem with out of memory when I'm trying load a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.