How do I get the suffix (in code) that is being used for urls?

Magento can add a suffix that is defined by the user to append onto urls. I want to get that suffix from my code. Does anyone know an easy way to do this?

4 thoughts on “How do I get the suffix (in code) that is being used for urls?”

  1. If it’s stored in the configuration area, then you access it just as you would any other configuration value, by using Mage::getStoreConfig($config_path) where $config_path is defined in the system.xml of the module that defines it.

    If you’re not sure of the $config_path, then I usually cheat and inspect the textbox/dropdown in the configuration section, take a look at the id, e.g. dev_log_file, and translate it to dev/log/file. You’ll need to use some intelligence when there are multiple _ though 🙂

  2. Nick’s answer is good but the actual answer to this question is:

    $suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
    

  3. If I am not mistaken, here is the code ( because I don’t understand what you want with URL )

    <?php
        $currentUrl = $this->helper('core/url')->getCurrentUrl();
        $url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
        echo $url_parts[0]; //check here
    ?>
    

  4. complete product url:

    $productId = ***;
    $productUrl  = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();
    

Leave a Reply

Your email address will not be published. Required fields are marked *