【问题标题】:Laravel 5.1 giving 404 Not Found except HomepageLaravel 5.1 给出 404 Not Found 除了主页
【发布时间】:2016-10-26 05:18:54
【问题描述】:

我在 Laravel 5.1 上建立了一个网站。它会在除主页之外的任何页面上引发 404 错误。但是,当我在 URL 中添加 index.php 时,它可以工作。我的网站在 Ubuntu 机器上运行,Nginx 作为 Web 服务器。

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

提供 404: mysite.com/dashboard

我在公用文件夹中的 .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>

感谢您的宝贵时间,如果能提供任何帮助,我将不胜感激。

编辑:

这是我的 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;
}

}

【问题讨论】:

    标签: php laravel laravel-5


    【解决方案1】:

    .htaccess 用于 Apache。它不适用于 Nginx。

    在你的 nginx 站点配置中试试这个(取自 Laravel 文档。)

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

    【讨论】:

    • 我的文件中有这个。见上文。
    • 对不起。我真的不经常使用 Nginx,所以我认为我无法进一步帮助您。
    猜你喜欢
    • 2015-10-13
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2013-03-10
    • 2012-12-22
    相关资源
    最近更新 更多