简体   繁体   English

codeigniter url基本路径不起作用/在前面

[英]codeigniter url base path not working/prepending

Hey so I am developing locally in Codeigniter and my project folder is: 嘿,所以我在Codeigniter中进行本地开发,我的项目文件夹是:

http://localhost/feeder_final/

When I do anything like: 当我做类似的事情时:

header('Location: /site_client/dashboard');

or click on an href='/site_client/' It redirects to: 或单击href ='/ site_client /'它将重定向到:

http://localhost/site_client/

Not: 不:

http://localhost/feeder_final/site_client/

I feel like I have tried everything... base_url, htaccess, etc, 我觉得我已经尝试了所有内容... base_url,htaccess等,

But I just can't get it to work. 但是我就是无法正常工作。 Thanks for any help. 谢谢你的帮助。

When you tried base_url , did you put brackets afterwards? 当您尝试base_url ,您之后是否放了括号? base_url() is a function so it needs brackets. base_url()是一个函数,因此需要使用方括号。 See the Codeigniter manual . 请参见Codeigniter手册 This should work: 这应该工作:

header('Location: '.base_url().'site_client/dashboard/');

or 要么

<a href="<?=base_url()?>site_client">site client</a>

Use base_url() for HTML assests like: Image, js & css, eg: 将base_url()用于HTML资产,例如:图片,js和CSS,例如:

<script src="<?php echo base_url('js/jquery.js'); ?>"></script>

Use site_url() for links, eg: 使用site_url()获得链接,例如:

<a href="<?php echo site_url('controller/function'); ?>">Link</a>

It's better to use base_url() or site_url() in case you will change your domain in the future. 最好使用base_url()或site_url(),以防将来将来更改域名。

Btw. 顺便说一句。 you can also use site_url('controller/method') same for redirection => redirect('controller/method') 您也可以使用site_url('controller / method')进行重定向=> redirect('controller / method')

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

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