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

Sven0188's avatar

Laravel 5 - Copied Entire Project to Sub-Folder | 404 Error

Good day Everyone,

I have made a copy of my 100% working Laravel web app on another domain/host. On the new domain, my Laravel projects sit in a subfolder for example: www.domain.com/laravel

When I browse to www.domain.com/laravel my home page loads perfectly without any errors. But as soon as I select any sub route I receive a 404 error. For example www.domain.com/laravel/register would not work.

Cleared all the cache files as well. Laravel 5.

Any guidelines on what to check and change when you make a precise copy of your website and paste it into a sub-folder on another domain (and host).

Thanks in advance :)

0 likes
10 replies
Snapey's avatar

Its not a recommended solution. You would need to mess with .htaccess as well as any urls that have been coded to be relative to the root '/'

Sven0188's avatar

Mmmm that is a pity because I do not have many alternatives. Someone wants to use my solution on their existing domain.

MaverickChan's avatar

maybe , you can change the port , like domain.com:8080 to run laravel , 80 to run original

Snapey's avatar

consider a subdomain

site2.customerdomain.com

then you can still have everything relative to root.

Sven0188's avatar

Awesome @snapey never thought about that one! So then I can have my file structure exactly is my working domain?

Snapey's avatar

yes. the site is not really aware it runs in a subdomain

Sven0188's avatar

Okay cool - I did just that. Cleared all cache: route, view, cache but still I can access my root route. Home page loads perfectly.

But when I browse to any child route I get Document not found.

Please any suggestion much appreciated :)

Sven0188's avatar

If have even setup a basic test Route::get() bit won't work.

Route::get("/test", function() {
	dd("Test");
});
Sven0188's avatar

Also cleared browser history. When change home route it works but no other child routes will work. My .env also updated to correct domain (sub).

Sven0188's avatar

Okay for future reference - got it solved. .htaccess file was the damn issue.

When I put /index.php/user then sub routes working.

My .htaccess that solved the issue:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

#php_flag register_argc_argv 1

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Please or to participate in this conversation.