skip to Main Content

I am working on laravel 5.5.33. I have created few pages like index.blade.php, about.blade.php etc. in view folder.

The routing for both the pages are working perfectly on local machine.
Then I migrated the project folder to my shared hosting.
The routing for the page index.blade.php is working perfectly but the same function is not working for any other file e.g 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>

4

Answers


  1. Try wrapping the path in the url() helper

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

    I’d also double check you have mod_rewrite switched on if apache (or whatever is the NGINX/{insert server here} equivalent)


    or even better add a name to your routes and then call that on the blade template:

    // 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');
    

    and

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

    You can get your route names from php artisan route:list and read about the helper here.

    Login or Signup to reply.
  2. Try this code:

    Route defined:

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

    controller code:

    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 Code:

    <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

    Login or Signup to reply.
  3. I Think You Have Just Moved You .htaccess file from the public or public_html folder.

    You have to copy it not cut/move it.

    Just paste a copy of .htaccess file in public or public_html folder and it’s done.

    Login or Signup to reply.
  4. just add this code on .htacces

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    And save the .htacces file in public_html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search