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

ruben777's avatar

root directory is displayed twice in URL on load and reload

I am trying to build an app using Laravel with Jetstream and Inertia + Vue.js.

URL looks like this : "https://website/app/route"

When I first visit the page, it loads and the URL changes to this : "https://website/app/app/route". The page displays its content correctly.

If I reload, I have a 404 message. I have to remove one "/app" to display the content the right way again.

If I don't reload, I can navigate on the page whithout any problem.

Anyone has an idea ?

0 likes
9 replies
Tray2's avatar

Check your links, routes and redirects so that you don't have an additional app somwhere.

ruben777's avatar

@Tray2 thank you for your answer. I found the problem : in vendor/inertiajs/inertia-laravel/src/Response.php there is a method called toResponse() ; the page url is built this way : $request->getBaseUrl() . $request->getRequestUri() which resulted in app/ (getBaseUrl) app/page/ (getRequestUri).

I overrided this file and removed $request->getBaseUrl() and now it works fine.

Neeraj1005's avatar

@ruben777 @tray2 I'm getting the same problem in my fresh Laravel app. Is there any other solution for this? I think overriding the framework file is not a good solution.

Snapey's avatar

@Neeraj1005 I agree. NEVER edit vendor files. Sounds like the getBaseUrl is returning an extra 'app' maybe down to incorrect app_url ?

1 like
ruben777's avatar

@Snapey I did not edit the vendor file. just overrided the class and modified the method

daleconway's avatar

I have the same issue.

I'm not sure if this will work in all instances, e.g. partial loads. I'm only new to intertia.js so I haven't had a chance to test it those out, but for a standard request, this should suffice.

Rather than edit my vendor folder, I put the following in the top of my app.blade.php

@php($page['url'] = App::make('request')->getRequestUri())

as the last line in toResponse() is

 return ResponseFactory::view($this->rootView, $this->viewData + ['page' => $page]);

As noted I'm not sure if it will work in cases where there is a X-Intertia header... as seen here in the toResponse() method

        if ($request->header('X-Inertia')) {
            return new JsonResponse($page, 200, ['X-Inertia' => 'true']);
        }

Please or to participate in this conversation.