Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Each route is showing 404 message on shared hosting

Tags:

php

laravel

I am trying to deploy a laravel application on A2Hosting shared hosting. My document root is: /public_html directory. I uploaded everything from my laravel application except the public folder to the /beta directory of hosting.

And then I uploaded everything from the public directory to the /public_html directory.

In my index.php file, I changed the following two lines:

require __DIR__.'/../beta/vendor/autoload.php';
$app = require_once __DIR__.'/../beta/bootstrap/app.php';

Now I am only seeing the home page of my application correctly. That is, mydomain.com. Any hyperlink followed by mydomain.com is showing a 404 message. In my view files, this is how I am referring to a path:

<a href="/login">Login</a>

But after deploying the application, whenever I hit that link, i.e. mydomain.com/login, I get the 404 Not Found: The resource requested could not be found on this server! message. I tried changing /login to login in the <a> tag. Same result. How do I solve this?

like image 931
Tanmay Avatar asked Oct 09 '17 13:10

Tanmay


People also ask

Why am I receiving a 404 not Found when I try to access a Route other than?

Error 404 not found is one of the most common issues you may encounter while browsing. This HTTP status code means the requested page can't be found on the website server. It may indicate a flaw with a hosting service or your domain name system (DNS) configuration settings.

Why is my website showing 404 error?

You might see a 404 error because of a problem with the website, because the page was moved or deleted, or because you typed the URL wrong. 404 errors are less common today than they used to be, as websites now strive to automatically redirect visitors away from deleted pages.


1 Answers

Eisenheim, this is htaccess issue: get one .htaccess file in root folder of your web-project.

And put the following code inside it,

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

Then try without index.php it should work perfectly.

like image 103
Himanshu Upadhyay Avatar answered Oct 20 '22 13:10

Himanshu Upadhyay