Twitter

How To Stop Redirect To Public Folder On Fresh Laravel 8 App

by Adam Patel

So, you’ve installed a fresh laravel 8 app on your shared web hosting account using Softaculous and now you’ve got this problem that when you go to your domain, it redirects to /public/ after 5 seconds.

Correcting this is a three step process.

Step 1 – Rename server.php as index.php in your root folder

That’s pretty self explanatory. Just select the server.php file and rename it as index.php, overwriting the current index.php file.

Step 2 – Move the contents of the public folder to the root folder

Again, self explanatory.

Step 3 – Open up your .htaccess file in the root folder and replace the content with the following…

<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>
Options -MultiViews -Indexes
 
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_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|trainer-cv)/(.*)$ public/$1/$2 [L,NC]

And that’s it! You’ll find the redirect has stopped and the splash screen now shows at yourdomain.com.

Copyright 2021. All Rights Reserved. Adam Patel