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

Rocks's avatar
Level 1

Api routes not found when hosted laravel application on server

I have created my application using laravel and vue.js and hosted my application on server in subfolder inside public_html, Accessing it using url like this:

https://maindomain.in/projectfolder/public/login

but after login if i click on any link it points back to

https://maindomain.in/dashboard

and i get 404 not found in console for the api routes that are accessed for eg. accessing dashboard

https://maindomain.in/api/backend/get-dashboatd-data

My root htaccess file content is :

<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force SSL
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Remove public folder form URL
    RewriteRule ^(.*)$ public/ [L]
</IfModule>

and content of .htaccess file inside public folder is

<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]

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

Note: Frontend is in Vue.js and backend in laravel.

0 likes
1 reply
jlrdw's avatar

Normally if you setup the correct folder structure, pointing to public as document root all will work.

https://laravel.com/docs/8.x/installation#directory-configuration

The documentation also states:

Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:

https://laravel.com/docs/8.x/deployment

In your url

https://maindomain.in/projectfolder/public/login

public shouldn't be in there.

However, also run: php artisan route:clear

3 likes

Please or to participate in this conversation.