简体   繁体   English

Laravel 5.1 给出除主页外的 404 Not Found

[英]Laravel 5.1 giving 404 Not Found except Homepage

I have a website set up on Laravel 5.1.我在 Laravel 5.1 上建立了一个网站。 It throws a 404 error on any page except the homepage.它会在除主页之外的任何页面上引发 404 错误。 However, when I add index.php in the URL, it works.但是,当我在 URL 中添加 index.php 时,它起作用了。 My site runs on a Ubuntu machine with Nginx as the web server.我的网站在 Ubuntu 机器上运行,Nginx 作为 Web 服务器。

Loads fine: mysite.com/index.php/dashboard加载正常: mysite.com/index.php/dashboard

Gives 404: mysite.com/dashboard给出 404: mysite.com/dashboard

My .htaccess in the public folder:我在公共文件夹中的 .htaccess:

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

    RewriteEngine On
    RewriteBase /


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

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

Thanks for your time and I would greatly appreciate any help.感谢您的时间,我将不胜感激任何帮助。

Edit:编辑:

This is my Nginx conf:这是我的 Nginx 配置:

server {
    server_name mysite.com;
    return 301 $scheme://www.mysite.com$request_uri;
}

server {
    listen       80;
    server_name www.mysite.com;

# note that these lines are originally from the "location /" block
root   /usr/share/web/site/public;
index index.php index.html index.htm;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }


error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/web/html;
}

location ~ \.php$ {
try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

  #  fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    fastcgi_max_temp_file_size 0;
    fastcgi_buffer_size 4K;
    fastcgi_buffers 64 4k;

    include        fastcgi_params;
}

}

A .htaccess is for Apache. .htaccess 适用于 Apache。 It will not work on Nginx.它不适用于 Nginx。

Try this in your nginx site configuration (taken from the Laravel documentation.)在你的 nginx 站点配置中试试这个(取自 Laravel 文档。)

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM