Magento – Get current url without parameters

geturlmagento-1.9template

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

Best Answer

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