B-219 Sec-55 Noida, India
+918010221733

Magento get current url with and without parameters

You can get the current page URL and it’s parameters (if any) by using getCurrentUrl() method in Magento. Below code will show you how to use it. Consider for example you have this url:

http://localhost/review/product/list/id/27/name/sony

To get this (current) URL in your module:

$currentUrl = $this->helper(‘core/url’)->getCurrentUrl();
//Gives: http://loca.lho.st/review/product/list/id/27/name/sony

To get current URL parameters:

$params = $this->getRequest()->getParams(); //all the parameters
//Gives: Array ( [id] => 27 [name] => sony )
$param = $this->getRequest()->getParam(‘name’); //parameter “name”
//Gives: sony

To get only URL without parameters:

$request = $this->getRequest();
$urlWithoutParameters = $this->getBaseUrl() . $request->getRouteName() .DS. $request->getControllerName() .DS. $request->getActionName();
//Gives: http://localhost/review/product/list

(Visited 524 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.