Welcome Guest, Not a member yet? Register   Sign In
Redirect strips trailing slash
#1

[eluser]matt.asbury[/eluser]
I have a redirect in my script which keeps stripping the trailing slash:
Code:
redirect("/backoffice/personnel/" . $this->input->post('id') . "/view/success/");
This redirects to the URL - http://..../backoffice/personnel/2/view/success

If I use the classic header redirect:
Code:
header("Location: /backoffice/personnel/" . $this->input->post('id') . "/view/success/");
this goes to the correct URL - http://..../backoffice/personnel/2/view/success/

Surely this points at the function itself. Any thoughts?

Matt
#2

[eluser]matt.asbury[/eluser]
It's ok guys, I traced the function through the framework and found that the trailing slash was being stripped in site_url() in the Config.php file of system/libraries:
Code:
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
and I needed to set what the suffix should be in the config file:
Code:
$config['url_suffix'] = "/";

Thanks
#3

[eluser]matt.asbury[/eluser]
I understand why you would say that but that doesn't apply in codeigniter does it? Each segment of the URL makes up /class/function/as/many/variables/as/you/need/. I add the trailing slash to give the URL a complete look as some users will see the final variable and expect to see something else there - .html, .php, .asp, etc.
#4

[eluser]sehummel[/eluser]
I tried adding the "/" to the config URL path and it doesn't get added. Actually, nothing does. I tried ".html" and it wasn't tacked on, either. What am I doing wrong?
#5

[eluser]Sheldon[/eluser]
Try adding this to your .htaccess file. (if you dont have one, add it, if your on windows, suck )

Code:
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

Mine looks similar to:
Code:
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

RewriteCond $1 !^(index\.php|assets|media)
RewriteRule ^(.*)$ /index.php/$1
#6

[eluser]Unknown[/eluser]
Thank you for the suggestion. I'll let you know if it Portfolio Recovery works.




Theme © iAndrew 2016 - Forum software by © MyBB