1

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

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Umer iqbal
  • 196
  • 1
  • 2
  • 15
  • you need to provide full url like (`http://google.com`) because on different browsers link without `http or https` taking project base url and append it automatically – Alive to die - Anant Apr 19 '17 at 05:39
  • your link is : http://localhost/my_project/job_classified/google.com so it is open but if you want open google.com then update your url – Shafiqul Islam Apr 19 '17 at 05:40

5 Answers5

2

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>
Community
  • 1
  • 1
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
1

try this

<a href="https://www.google.com">click me</a>
sandip kakade
  • 1,346
  • 5
  • 23
  • 49
1

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.

Pupil
  • 23,834
  • 6
  • 44
  • 66
1

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

1

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>
Tpojka
  • 6,996
  • 2
  • 29
  • 39