Welcome Guest, Not a member yet? Register   Sign In
Redirect, it works only with one parameter

If a wrong page is requested I want to show a "page not found" view.
To do this I'm using the redirect() function, but I'm having a problem.

If I use
the page is shown

while if I use
redirect('/home/page_not_found', 'location', 404);
I get a blank page.

There is no output before the redirect function, what can cause the problem?

[eluser]TWP Marketing[/eluser]
redirect() is a CI URL helper function and only accepts the URL parameter.
If you want to use more parameters, try the full php http_redirect()
Check the User Guide for the specifics of the helper function.
bottom of this page: http://ellislab.com/codeigniter/user-gui...elper.html

I read the user guide, and that's why I was using that syntax.
In the user guide you can read what follows

Does a "header redirect" to the URI specified. If you specify the full site URL that link will be build, but for local links simply providing the URI segments to the controller you want to direct to will create the link. The function will build the URL based on your config file values.

The optional second parameter allows you to choose between the "location" method (default) or the "refresh" method. Location is faster, but on Windows servers it can sometimes be a problem. The optional third parameter allows you to send a specific HTTP Response Code - this could be used for example to create 301 redirects for search engine purposes. The default Response Code is 302. The third parameter is only available with 'location' redirects, and not 'refresh'. Examples:
if ($logged_in == FALSE)
     redirect('/login/form/', 'refresh');

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

[eluser]TWP Marketing[/eluser]
You're correct.
Is your redirect() being issued before any attempts to load a view (or fractional view) to the browser?
For instance, do you load some header view(s) before making a conditional test for the existence of a page which might trigger redirect? I assume this conditional statement is in your controller.

Did you set $route['404_override'] for the default router to use on 404's?

Theme © iAndrew 2016 - Forum software by © MyBB