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

samukobo's avatar

URL duplicates in shared hosting deployed Inertia App

I've recently tried to put an Inertia app with Vue 3 and Laravel 8 on my personal server (shared hosting with Hostinger). The assets are built live, and the contents of the public/ folder are moved to a subfolder in public_html, like so:

/ root_of_server
| - project_core (everything except public/)
| - domains
    | - mydomainname.com
        | - public_html
            | - project (the public folder)

Here's what my routes/web.php looks like:

Route::get('/', function () {
    return Inertia::render('Home');
});

Route::get('/github', function() {
    return Inertia::render('Github');
});

However, the URL in the browser is rewritten whenever I access a page.

https://www.mydomainname.com/project turns into https://www.mydomainname.com/project/project

The same thing happens with the other route. https://www.mydomainname.com/project/github turns into https://www.mydomainname.com/project/project/github

Checking with vue devtools, Inertia.initialPage.url seems to be set to the incorrect value (the one with a duplicate)

Would anyone know how to solve this? I can't find anyone with the same issue. Here's the github link to the project: https://github.com/samuelkirbyaguilar/mimic/tree/github

0 likes
5 replies
samukobo's avatar

Using ddd($request) shows this for the relevant route:

requestUri: "project/github"
baseUrl: "/project"

Which is why Inertia's Response::toResponse($request) method, which passes url => $request->getBaseUrl().$request->getRequestUri() to the page was passing the wrong url.

Seems like this might be an issue with how the app was deployed, i.e. I need to use a subdomain instead of a subfolder. If anyone knows how to change either the requestUri or the baseUrl to what's appropriate, please reply to this post.

1 like
Sinnbeck's avatar

@samukobo if the site works as expected locally, my bet is that it's related to how you set up the structure on shared hosting

Try explaining your exact setup (folder structure and such) and someone else who uses shared hosting can give you some tips

bhavin-zwt's avatar

@samukobo Do you find any proper way to solve the issue? We are also facing this issue. Thanks

joydeep's avatar

One more similar issue's solution: - if anyone running Laravel in cPanel shared hosting and getting /public/public in your URL . open vendor/inertiajs/src/Response.php and replace

$page = [
            'component' => $this->component,
            'props' => $props,
            'url' => $request->getBaseUrl().$request->getRequestUri(),
            'version' => $this->version,
        ];

with

$page = [
            'component' => $this->component,
            'props' => $props,
            'url' => str_replace("/public", "", $request->getBaseUrl().$request->getRequestUri()),
            'version' => $this->version,
        ];

Please or to participate in this conversation.