Redirect to absolute URL |
[eluser]maesk[/eluser]
Hi, 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 Code: header('Location: http://www.example.com/'); for these cases or is there a CI specific method to do this?
[eluser]maesk[/eluser]
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 Code: http://www.mypage.com/controller1/function1 when I am at Code: http://www.mypage.com/controller2/function1/ I can't just do a Code: redirect('controller1/function1'); because this would take me to the URL http://www.mypage.com/controller2/functi.../function1 If I use Code: redirect(site_url('controller1/function1')); 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.
[eluser]OES[/eluser]
Hi you can redirect to anywhere so like you have said add a forward slah to make it a root redirect ie. redirect('/controller2/function2/'); Regards Lee
[eluser]maesk[/eluser]
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! maesk |
Welcome Guest, Not a member yet? Register Sign In |