Naresh
Naresh

Reputation: 73

How to get Base URL along with href

Presently I'm in this location :

localhost/magento/dresses/adidas-t-shirt.html

I wrote in my file like this

<a href="my/hello/">Click Here</a>

When I click on Click Here

I am getting like

localhost/magento/dresses/my/hello/

But actually I'm tryng to get like this

localhost/magento/my/hello/

How can I get this one?

Upvotes: 0

Views: 2710

Answers (5)

Steve Robbins
Steve Robbins

Reputation: 13812

I believe you're looking for

echo $this->getUrl("my/hello");

Upvotes: 0

siddharth
siddharth

Reputation: 231

Do you have a base URL set for the application? if not then set a base URL and you can do something like this,

<a href="<?php echo base_url(); ?>my/hello/">Click Here</a>

I am not sure about whether you are asking from Megento, if you are then take a look at this. It might be of some help,

http://www.magentocommerce.com/boards/viewthread/8812/

Upvotes: 0

Marius
Marius

Reputation: 15206

The correct way to get an URL is:

$url = Mage::getUrl('my/hello');

This will give you an url like this: magento_root/my/hello/. If you want it without the slash at the end use

$url = Mage::getUrl('', array('_direct'=>'my/hello'));

Upvotes: 0

marcinsdance
marcinsdance

Reputation: 654

Your link should be:

<a href="/my/hello/">

or if you are in a phtml file, you may want to use Magento's native function:

<?php echo Mage::getBaseUrl('...'); ?>

Upvotes: 0

liyakat
liyakat

Reputation: 11853

you can also try with below as per magento standard

<?php
$_getBase = Mage::app()->getStore()->getBaseUrl();
?>
<a href="<?php echo $_getBase; ?>my/hello/">Link</a>

Upvotes: 1

Related Questions