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

WallyJ's avatar

Route works to show correct URL, but get 404

I moved a site to a new server, and now when I visit the site URL, it automatically takes me to www.site.com/login as the route is designed, but then I get a 404.

I thought I adjusted to .env and index.php files correctly for the directory structure and new site address.

Is there another file I should edit?

0 likes
8 replies
Snapey's avatar

why are you needing to edit the index.php file. That is a BIG RED WARNING SIGN in my book.

You should set the document root to be the public folder and DONT mess with index.php

jlrdw's avatar

If it's taking you to www.site.com/login something is correct.

What change did you make in index.php. The problem is probably a "hard coded" redirect instead of a relative url.

siangboon's avatar

it's unlikely need to change .env nor index.php as it's irrelevant in routing, you need to ensure the document root, .htaccess and web.php are set correctly, especially typo error or case sensitivity issue...

WallyJ's avatar

Don't you need to set the APP_URL in the .env?

I have placed all of my app files into a subdirectory (myapp) in the root (same level as public_html), so I have to change two lines in index.php, right:

require __DIR__.'/../myapp/vendor/autoload.php';

$app = require_once __DIR__.'/../myapp/bootstrap/app.php';
WallyJ's avatar

Side note. I figured out that it is only a problem with the VPS temporary URL. Once the domain is pointed it works just fine.

Why is that?

The temp URL looks like: www.hostingcompany.com/~username

I think it's the username folder/redirect that messes up Laravel.

Snapey's avatar

if you are changing the directory structure and/or index.php then you are playing a dangerous game

WallyJ's avatar

That is a bit non-descript. I have seen multiple tutorials on how to do this to have the web root above the other project files. I know that it is an issue of security, but I need to be able to place my project files in such a way that they work.

Natively, the "public" folder cannot be dropped into the "public_html" folder and it work correctly. And not all VPS's have access to change their Apache config files.

As always, @snapey , I appreciate your input. :)

Snapey's avatar

put the laravel project in the parent of public_html

copy the content of public folder into public_html

It should work like that. The only problem will be the public() helper

But I dont understand. If its a VPS then you should have full contol over the directory structure and the document root

Please or to participate in this conversation.