I have looked all over the internet, but can not find the following answer:
We want to get the part in Magento in .phtml after the main url so if:
domain.com/shoes.html we want to get only shoes.html
This is important because we have a multishop in .nl and .be and we want to use the hreflang. We need to give in both shops the url of both shops so as well from the .be and the .nl and then with the subcategory or product url.
In .phtml you can get the current url with: helper('core/url')->getCurrentUrl();?>
With that code you will get the total url so domain.com/shoes.html and we only want the part shoes.html
Would be great if someone knows the answer
If you need to get current URL in Magento 2 PHTML file the easiest way to do this is to use the following code: $currentUrl = $block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]); This is the best method since you don't even need to use the Object Manager.
Default Base URL: http://yourdomain.com/magento/ Default Admin Path: admin.
$currentUrl = Mage::helper('core/url')->getCurrentUrl()
or
$currentUrl = Mage::getUrl('*/*/*', array('_current' => true));
above code may not work always as expected. Better way to find the current url is to use the following code:
if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) {
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
}
You could do this:
$urlString = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($urlString);
$path = $url->getPath();
$path will contain the URL excluding the domain name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With