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

MooseSaid's avatar

Redirects not working (No 'Access-Control-Allow-Origin' header) - Laravel InertiaJS and Vue

I'm working with this form that submits a store request to create a product, then I'm trying to return and redirect to view the product.

It was working yesterday and today it decided to fail with the below error:

Access to XMLHttpRequest at 'http://user.example.test/my-first-product' (redirected from 'http://example.test/products/create') from origin 'http://example.test' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I'm using Laravel with InertiaJS and VueJS and I swear the redirect was working yesterday without a problem and today it's not working for some reason. I'm using normal example.test URL flow for the homepage but for viewing the product I'm using subdomains like user.example.text/the-product

this is the redirect line:

public function store(StoreProductRequest $request)
    {
		
		// Code
		
        return redirect()->route('products.show', [$user, $product]);
    }

This is the route of the redirect:

Route::domain('{user:username}.' . env('APP_URL'))->group(function () {

    Route::get('{product:slug}', [ProductController::class, 'show'])->name('products.show');
    
});

Product show:


    public function show(User $user, Product $product)
    {
        return Inertia::render('Products/Show', [
            'user' => $user,
            'product' => $product,
            'thumbnails' => $product->productimages
        ]);
    }

I looked everywhere for a solution but all what I found 4 5 years old solutions with installing packages to solve the issue while I'm 100% confident that it was working yesterday without packages, I tried to chase any changes I made but nothing related to the issue.

0 likes
4 replies
MooseSaid's avatar

@KevinKirchner I tried this, It works but I have to do something like this

 return Inertia::location('http://' . $user->username . '.example.test/' . $validated['slug']);

But It causes a full page refresh and I will have to remember changing 'http' to 'https' and domain to the real domain when I'm going to put the app in production. I was hoping that I was doing something wrong but after hours of searching for a solution I began to think that Laravel Inertia apps doesn't support subdomain redirects

1stevengrant's avatar

@KevinKirchner I keep forgetting about this. We're using Auth0 for authentication on a project and we couldn't get to the login screen on certain auth routes because of this.

MooseSaid's avatar

I found a solution that solved for me the CORS errors from this Stackoverflow answer but I'm facing an issue where it redirects me to a url that ignores the subdomain completely. Find the new issue here please

Please or to participate in this conversation.