简体   繁体   中英

anchor tag weird behaviour in codeigniter

i have controller by name"job_classified" the problem is when i open

<a href="google.com"> click me </a> 

in view it opens http://localhost/my_project/job_classified/google.com instead of google.com

what actually is the problem? i tried other code igniter URI functions but it didn't work for me.can someone guide me how to do it correctly

Why your code doesn't work is described here:- https://stackoverflow.com/a/2005097/4248328

So do like below:-

<a href="https://www.google.com">click me</a>

尝试这个

<a href="https://www.google.com">click me</a>

Please change url to:

<a href="http://www.google.com"> click me </a>

Reason: HTML parses urls as of relative ones if no http or https is given.

HTML server in your case considers google.com as a relative file is the same directory.

In Codeigniter you can do it a couple of ways

Using the base_url from the url helper

Note: the base url in config.php must be set

https://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url

<a href="<?php echo base_url('job_classified');?>">Some Name</a>

<a href="<?php echo base_url('controller/function');?>">Some Name</a>

Also you can use the anchor();

https://www.codeigniter.com/user_guide/helpers/url_helper.html#anchor

<?php echo anchor('job_classified', 'Job Classified');?>

<?php echo anchor('controller/function', 'Job Classified');?>

How to remove index.php from url https://github.com/wolfgang1983/htaccess_for_codeigniter

Always prepend URLs with double slash. That way you don't need to think whether location should be http or https.

<a href="//google.com">This way browser will automatically</a>

<a href="//www.google.com">determine which scheme to use</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM