User1980's avatar

http/1.0 302 Found Cache-Control: no-cache,private redirect issue

Hello,

No idea if you ever had this issue but when my users click a link via email, they hit this URL:

https://xxxxxxx.com/ad/expired/9410

The controller is then reached:

Route::get('/ad/expired/{id}', 'Common\adController@expires');

And this is returned:

        return redirect()->route('ads');

It looks like the return redirect causes a blank page (for 1 second) with the below message:

http/1.0 302 Found Cache-Control: no-cache,private redirect issue

Just before the correct page shows up.

Any idea why please?

Thanks

0 likes
11 replies
User1980's avatar

thanks yes I tried that right away but the same issue happens. I have also clearing Laravel with:

php artisan cache:clear
php artisan view:clear
php artisan config:clear
php artisan config:cache
php artisan route:cache
User1980's avatar

Yes I checked this thread already and my URL is fine.

neilstee's avatar

@user1980 can you check if you are echoing something in the process? Like new lines in the opening PHP tags or something.

HallOfCode's avatar

In my case a false return-type declaration triggers that problem. Ive used :string declaration at a function which is returning a redirect().

I write this for every people who have this issue in the future.

3 likes
Sinnbeck's avatar

@HallOfCode can you show an example, for better understanding of what to look for?

I assume

public function redir(): string
{
    return redirect()->route('ads');
} 
HallOfCode's avatar
Level 1

@Sinnbeck Sry forgot to Login in Laracast. In my case the Issue pops out because I've had a function in my controller like this:

//FalseController.php

public function some(): string 
{
		return redirect()->route('home');
}

Then this redirect Issue exists because the return type of the function is set as string but the function returns a redirect.

Just fixed the issue by removing the : string from my function. Like that:

//RightController.php

public function some() 
{
		return redirect()->route('home');
}

//or replacing it by the redirect-type (didnt know the namespace right now)

Hope that helps.

5 likes
User1980's avatar

@HallOfCode Oh wow! I had the same problem agian today lol. Could not work out, your saved my life! Phpstorm added ": string" like you at the end of my function.

User1980's avatar

I will close this thread as it is an old thread but the reason I was getting this was that in my blade templating, I had twice the header data getting passed(I duplicated the header code by mistake). I cannot give you the exact code as it was over 5 months ago....

Please or to participate in this conversation.