簡體   English   中英

Laravel 5.1 給出除主頁外的 404 Not Found

[英]Laravel 5.1 giving 404 Not Found except Homepage

我在 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;
}

}

.htaccess 適用於 Apache。 它不適用於 Nginx。

在你的 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