Laravel路由在本地服务器上工作但不在cpanel上工作

时间:2018-02-02 13:13:22

标签: php laravel

我正在研究laravel 5.5.33。我在视图文件夹中创建了一些页面,如 index.blade.php about.blade.php 等。

这两个页​​面的路由在本地计算机上完美运行。 然后我将项目文件夹迁移到我的共享主机。 页面 index.blade.php 的路由工作正常,但同样的功能不适用于任何其他文件,例如 about.blade.php

web.php

// This function is working for index file
 Route::get('/', function () {
    return view('index');
});

// This function is not working for about file
Route::get('about', function () {
    return view ('about');
});

header.blade.php

<ul>
<li class="mega-menu"><a href="/">Home</a></li>
<li class="mega-menu"><a href="about">About Us</a></li>
<ul>

3 个答案:

答案 0 :(得分:0)

尝试在url()帮助程序中包装路径

<li class="mega-menu"><a href="{{url('/about')}}">About Us</a></li>

如果apache(或者NGINX / {insert server here}等价物)

,我还会仔细检查你是否mod_rewrite已开启

甚至更好地为您的路线添加名称,然后在刀片模板上调用该名称:

// This function is working for index file
 Route::get('/', function () {
    return view('index');
})->name('index');

// This function is not working for about file
Route::get('about', function () {
    return view ('about');
})->name('about');

<li class="mega-menu"><a href="{{route('about')}}">About Us</a></li>

您可以从php artisan route:list获取路线名称并阅读帮助here

答案 1 :(得分:0)

我认为您刚刚移动了public或public_html文件夹中的.htaccess文件。

您必须复制它,而不要剪切/移动它。

只需将.htaccess文件的副本粘贴到public或public_html文件夹中即可。

答案 2 :(得分:-1)

试试这段代码:

路线定义:

Route::get('/', 'HomeController@index');
Route::get('about', 'HomeController@about');

控制器代码:

public function index()
{
    return view('homes.index'); // homes is folder name and index is index.blade.php , below follow image .
}


public function about()
{
    return view('about.about');
}

Html代码:

<ul>
<li class="mega-menu"><a href="{{('/')}}">Home</a></li>
<li class="mega-menu"><a href="{{ url('about')}}">About Us</a></li>
<ul>

enter image description here