CodeIgniter Forums
trailing slash in $config['base_url'] and start slash in redirect() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: trailing slash in $config['base_url'] and start slash in redirect() (/showthread.php?tid=32707)



trailing slash in $config['base_url'] and start slash in redirect() - El Forum - 08-01-2010

[eluser]searain[/eluser]
In configuration,

URL to your CodeIgniter root. Typically this will be your base URL, WITH a trailing slash:
$config['base_url'] = "http://www.your-site.com/";

In document

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

redirect()

if ($logged_in == FALSE)
{
redirect('/login/form/', 'refresh');
}

// with 301 redirect
redirect('/article/13', 'location', 301);

My questions are:

1) the base_url already have a slash and the end, does redirect() needs a slash at the beginning? Is that duplicated? Or better practice is with or without start slash in redirect(), someone said need the start slash someone said no. What is the authenticate answer? Thanks!

2) It seems CodeIgniter already takes care of the case that if $config['base_url'], missing the trailing slash. Such as with or without trailing slash, base_url() would always return with trailing slash. What is the common error you can see if missing the trail slash in the $config['base_url']?

Thanks!


trailing slash in $config['base_url'] and start slash in redirect() - El Forum - 08-01-2010

[eluser]Militis[/eluser]
I never use a beginning slash in redirect (or ending one for that matter). It doesn't seem to make any difference. Without digging through the core, I believe that it checks for and adds/removes the slash if needed.