codeigniter url 基本路径不是 working/prepending
codeigniter url base path not working/prepending
嘿,所以我在 Codeigniter 本地开发,我的项目文件夹是:
http://localhost/feeder_final/
当我做类似的事情时:
header('Location: /site_client/dashboard');
或者点击 href='/site_client/'
它重定向到:
http://localhost/site_client/
不是:
http://localhost/feeder_final/site_client/
我觉得我什么都试过了...base_url、htaccess 等
但我无法让它工作。感谢您的帮助。
当你尝试base_url
的时候,你后面有没有加括号? base_url()
是一个函数,所以它需要括号。参见Codeigniter manual。这应该有效:
header('Location: '.base_url().'site_client/dashboard/');
或
<a href="<?=base_url()?>site_client">site client</a>
最好使用 base_url() 或 site_url() 以防您将来更改域。
顺便说一句。您也可以使用 site_url('controller/method') 相同的重定向 => redirect('controller/method')
将 base_url() 用于 HTML 评估,例如:图像、js 和 css,例如:
<script src="<?php echo base_url('js/jquery.js'); ?>"></script>
对链接使用site_url(),例如:
<a href="<?php echo site_url('controller/function'); ?>">Link</a>
嘿,所以我在 Codeigniter 本地开发,我的项目文件夹是:
http://localhost/feeder_final/
当我做类似的事情时:
header('Location: /site_client/dashboard');
或者点击 href='/site_client/' 它重定向到:
http://localhost/site_client/
不是:
http://localhost/feeder_final/site_client/
我觉得我什么都试过了...base_url、htaccess 等
但我无法让它工作。感谢您的帮助。
当你尝试base_url
的时候,你后面有没有加括号? base_url()
是一个函数,所以它需要括号。参见Codeigniter manual。这应该有效:
header('Location: '.base_url().'site_client/dashboard/');
或
<a href="<?=base_url()?>site_client">site client</a>
最好使用 base_url() 或 site_url() 以防您将来更改域。
顺便说一句。您也可以使用 site_url('controller/method') 相同的重定向 => redirect('controller/method')
将 base_url() 用于 HTML 评估,例如:图像、js 和 css,例如:
<script src="<?php echo base_url('js/jquery.js'); ?>"></script>
对链接使用site_url(),例如:
<a href="<?php echo site_url('controller/function'); ?>">Link</a>