Welcome Guest, Not a member yet? Register   Sign In
Redirect to absolute URL


the URL Helper's redirect() function does a header redirect to a local URI, that is a relative URL. Sometimes, however, I'll have to redirect to an absolute URL, for example when I have an optional number of parameters for my controller. Should I just use

header('Location: http://www.example.com/');

for these cases or is there a CI specific method to do this?

Just redirect(''); will do the trick.

Good Luck !

That's one reason why I love CodeIgniter: you have a question, you get an answer in 5 minutes on the forums... awesome!
However, I probably didn't explain properly what I wanted to achieve. Your solution would just redirect me to my homepage (the base_url), but that's not what I want.

Let's say I want to be redirected to


when I am at


I can't just do a


because this would take me to the URL http://www.mypage.com/controller2/functi.../function1

If I use


it would take me to http://www.mypage.com/controller2/functi.../function1

It would be useful if the redirect() function could be used relative AND absolute, for example when it would use an absolute URL as soon as site_url() is included.
But I guess I have to use something like custom routes for this.

Edit: some of you are probably going to suggest to simply remap controller1/function1 to controller2/function1 but I want to redirect only under certain conditions, such as when there are no params in the URL but POST data exists.


you can redirect to anywhere so like you have said add a forward slah to make it a root redirect ie.




Cool, it works!! This was much easier than I thought - just add the slash at the beginning... I wouldn't have tought of that (duh!).
Thanks a lot!

Theme © iAndrew 2016 - Forum software by © MyBB