简体   繁体   English

为什么我在CodeIgniter中没有正确重定向到base_url()?

[英]Why I'm not redirected properly to base_url() in CodeIgniter?

While clicking on this button, I'm not being redirected to base_url(), but to 'current_url'/base_url(). 单击此按钮时,不会重定向到base_url(),而是重定向到'current_url'/ base_url()。

Line in config/config.php: 在config / config.php中输入:

$config['base_url'] = 'localhost/projekt/'; 

Code in header: 标头中的代码:

<a class="navbar-brand" href="<?php echo site_url(); ?>">Nav</a>

I'm being redirected to site 'localhost/projekt/localhost/projekt/', instead of 'localhost/projekt/'. 我被重定向到站点“ localhost / projekt / localhost / projekt /”,而不是“ localhost / projekt /”。

I can't find any solution on the web. 我在网络上找不到任何解决方案。 Is there a way to do this properly? 有没有办法正确地做到这一点? Thanks in advance. 提前致谢。

Because your href does not start with http:// or / so the browser will simply append the url into your current url. 由于您的href并非以http:///开头,因此浏览器会将网址简单地附加到当前网址中。

Take a look at the difference here: https://jsfiddle.net/ChinLeung/c1t6vw4v/ 看看这里的区别: https : //jsfiddle.net/ChinLeung/c1t6vw4v/

To fix it, change your config to: 要解决此问题,请将您的配置更改为:

$config['base_url'] = 'http://localhost/projekt/';

change line in config/config.php: 更改config / config.php中的行:

$config['base_url'] = 'localhost/projekt/'; 

it will be 这将是

$config['base_url'] = 'http://localhost/projekt/';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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