Home > Backend Development > PHP Tutorial > laravel5.2 blog页面跳转404错误

laravel5.2 blog页面跳转404错误

WBOY
Release: 2016-06-06 20:06:16
Original
1370 people have browsed it

项目为laravel网站上的项目:http://laravelacademy.org/post/2265.html

当部署完成后,用浏览器打开首页出现 /blog not found 的404错误。

routes.php代码如下:

<code><?php Route::get('/', function () {
        return redirect('/blog');
    });

    Route::get('blog', 'BlogController@index');
    Route::get('blog/{slug}', 'BlogController@showPost');
?></code>
Copy after login
Copy after login

尝试操作:

  1. 直接取消redirect重定向,修改成:

<code><?php Route::get('/', 'BlogController@index');
    Route::get('/{slug}', 'BlogController@showPost');
?></code>
Copy after login
Copy after login

并修改视图中的跳转链接,将 /blog/{slug} 修改成 /{slug}
结果,主页是出来了,但是二级页面还是出不来。提示404 notfound!

源码链接:https://github.com/digjack/Blog

回复内容:

项目为laravel网站上的项目:http://laravelacademy.org/post/2265.html

当部署完成后,用浏览器打开首页出现 /blog not found 的404错误。

routes.php代码如下:

<code><?php Route::get('/', function () {
        return redirect('/blog');
    });

    Route::get('blog', 'BlogController@index');
    Route::get('blog/{slug}', 'BlogController@showPost');
?></code>
Copy after login
Copy after login

尝试操作:

  1. 直接取消redirect重定向,修改成:

<code><?php Route::get('/', 'BlogController@index');
    Route::get('/{slug}', 'BlogController@showPost');
?></code>
Copy after login
Copy after login

并修改视图中的跳转链接,将 /blog/{slug} 修改成 /{slug}
结果,主页是出来了,但是二级页面还是出不来。提示404 notfound!

源码链接:https://github.com/digjack/Blog

在 Nginx,在你的网站配置中增加下面的配置,可以使用「优雅链接」

<code class="php">location / {
    try_files $uri $uri/ /index.php?$query_string;
}</code>
Copy after login

或者/index.php/blog

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template