3

How can I get current url without utm parameters for example? I need this in phtml templates. Thank you.

EDIT

EXAMPLE:

From url

www.example.com/post?utm_source=google&utm_medium=cpc&utm_campaign=campaign

I need to get only

www.example.com/post

7 Answers 7

8

The cleanest way to do that is:

echo $this->getUrl('*/*/*', array('_use_rewrite' => true, '_forced_secure' => true));
  • The first parameter '*/*/*' means that you stay on the same module/controller/action
  • The second parameter is an array of options

The option '_use_rewrite' let you keep the rewrited url, for example:

/my-category/my-product-url-key/ instead of /catalog/product/view/id/456/category/123

The option '_forced_secure' will be useful for website having SSL enabled.

There are other options that you can find documented here: http://dltr.org/blog/magento/418/Magento-get-url-with-or-without-parameters

1
  • How can you do that with a specific store wise?
    – Mohit Rane
    Jan 19, 2021 at 9:01
2

It's much more simple. You can simply get the original path info.

Mage::app()->getRequest()->getOriginalPathInfo();
1
  • the return for this, for example "checkout_cart_index"
    – Ansyori
    Apr 20, 2017 at 7:25
1

You can get current url without parameters

$request = $this->getRequest();
$urlWithoutParameters = $this->getBaseUrl() . $request->getRouteName() .DS. $request->getControllerName() .DS. $request->getActionName();

You can get current url like this

 echo $this->helper('core/url')->getCurrentUrl();

if this is not work than you can refer here

Hope this will help you

4
  • That isnt exactly what I was looking for. For example: at this url www.example.com/?utm_source=google&utm_medium=cpc&utm_campaign=campaign I need to get only www.example.com/
    – sidlo
    Mar 19, 2015 at 10:40
  • You want to domain name only ri8?
    – ND17
    Mar 19, 2015 at 11:12
  • Bad example, sorry. I want to get rid of the parameters.
    – sidlo
    Mar 19, 2015 at 11:14
  • check my update
    – ND17
    Mar 19, 2015 at 11:35
1

I am using

$urlWithoutParameters = Mage::getBaseUrl() . $request->getRouteName() .DS. $request->getControllerName() .DS. $request->getActionName();
1

Best way to get URL without any parameters,

 $this->getUrl("*/adminhtml_report_brands/index", array("_current" => false))
0

I was using my application under /magento directory. This helped me to get URL without any parameter.

<?php echo Mage::app()->getRequest()->getBasePath().Mage::app()->getRequest()->getOriginalPathInfo(); ?>

Hope this helps you!!

0

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://loca.lho.st/review/product/list
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.