Laravel routes are not working on production server 404 error

余生长醉 提交于 2019-12-22 08:59:16

问题


I have a laravel project, which is working fine on the local machine, where I have it set up on homestead, but when I have uploaded project to the production server on namecheap, none of the links or routes are working, I only get the index page open with no style, and if I click on any of the links I get 500 error. I have follow the suggested steps here:

So, my laravel project directory is in the same level as public_html, as well as public directory from my laravel project. They are all in the same directory level. And I have changed the paths in the index.php file:

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

Then, I have changed the server.php inside the laravel project directory:

require_once __DIR__.'../public_html/index.php';

Permission were set apparently by the namecheap customer service, but I still get 404 error for all my css and js files, as well as when clicking on some html links on my page.

In the view file I am calling my css files like this:

<!-- CSS Files -->
  <link href="{{ asset('css/material-kit/css/bootstrap.min.css') }}" rel="stylesheet" />
  <link href="{{ asset('css/material-kit/css/material-kit.css') }}" rel="stylesheet"/>
  <link href="{{ asset('css/landing-page.css') }}" rel="stylesheet"/>

And js file the same way:

<!--   Core JS Files   -->
<script src="{{ asset('js/landing-page/jquery.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/landing-page/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/landing-page/material.min.js') }}"></script>

<!-- Control Center for Material Kit: activating the ripples, parallax effects, scripts from the example pages etc -->
<script src="{{ asset('js/landing-page/material-kit.js') }}" type="text/javascript"></script>

Not sure how can I fix that?

Update

I have managed to fix the css and js issue of not opening the files, I have moved the files to the wrong directory by mistake. But I still can't get any links on the page to work?

In my view I have links like this one:

<a href="{{ url('/login') }}">Login</a>

And when clicking on them I get 404 error.


回答1:


You need to set up Laravel project in shared hosting which is well explained here.

After you succeed thru all 7 steps your project should work fine on server.

Also add this to your .htacces file in public_html

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^ index.php [L]

Hope it helps




回答2:


Options -MultiViews

RewriteEngine On
RewriteBase /laravel51/public/

# change above to your site i.e., RewriteBase /whatever/public/

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

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

In .htaccess file has to change



来源:https://stackoverflow.com/questions/41678300/laravel-routes-are-not-working-on-production-server-404-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!