I am printing my custom URL's in footer which I am getting from database, Some thing like this Assume this contains www.google.com link.

 <li><a href="<?php echo $links['link_url']?>"><?php echo $links['title'] ?></a></li>

When I click on this link at footer it rediecting with my current page url www.mydomainname.com/www.google.com

How can I avoid attaching my current domain name to it? It should be redirect to "www.google.com"


What you are viewing is the default behaviour <a /> HTML tag. if the parameter specified in the href section is a relative term, then browser will append that parameter to the current url, while clicking on that link.

Here the parameter is www.google.com. For browser, it is a relative term and hence it is appending it to the current URL. Hence url will turn into [your_current_url]/www.google.com.

The solution is use the absolute url instead of relative term. ie use http:://www.google.com. ie your link should look like this.

<li><a href="http:://<?php echo $links['link_url']?>">
    <?php echo $links['title'] ?>

or simply

<li><a href="//<?php echo $links['link_url']?>">
     <?php echo $links['title'] ?>

That will do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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