Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Abodshd's avatar

302 Not found with Get method

I'm working with Laravel and I'm having trouble with a 302 Found status. I'm using a GET route that changes the language, saves the session, then redirects back or to the dashboard if there's no HTTP referrer. The code and route work fine in another project on the server, so I'm not sure what the issue is. I've tried clearing config cache, route cache, and other caches, but the problem persists. I also tried changing the URL, but the issue remains. Any ideas on what could be causing this? That's the code guys.

Route::get('/switch_language/{language}', [SubscriptionHomeController::class, 'switch_lang']);

public function switch_lang($language = "") {

    session()->put('my_site_lang', $language);
    session()->save();


    if (!empty($_SERVER['HTTP_REFERER'])) {
        return redirect($_SERVER['HTTP_REFERER']);
    } else {
        return redirect('/subscription/dashboard');
    }
}

//Blade code @foreach (get_language() as $lang) {{$lang->name}} @endforeach

0 likes
12 replies
vincent15000's avatar

Do you see the route when you list the routes in the console ?

php artisan route:list
Snapey's avatar

Is language set in session?

Isn't your code the same as back() ?

2 likes
Abodshd's avatar

@Snapey yes sir language is set in session . Yes, HTTP_REFFER is the same as back().

1 like
Abodshd's avatar

@Snapey I'm getting 302 Found status but I have no idea why

1 like
Snapey's avatar

@Abodshd As @jussimannisto says. 302 code is what you would expect if you return a redirect. The headers of the response contain the URL that the browser should redirect to.

1 like
Abodshd's avatar

@Snapey but why the lang isn't changing I've tried this in another project and the lang is changing but here it's not and It's giving 302

1 like
JussiMannisto's avatar

@Abodshd What are you talking about? You're returning a redirect. That has a 302 status code. That's how the browser knows to perform a redirection.

What do you think should happen?

1 like
Snapey's avatar

@Abodshd How are you testing? You should expect a 302, then follow that redirection with the same session to know if the session language is set

Please or to participate in this conversation.