skip to Main Content

I’ve been working on a Laravel project using a Bootstrap template, and everything works perfectly locally. However, as soon as I deployed my project on a shared server, I encountered a routing issue.

Specifically, when I load the homepage, everything works fine. However, when I click on navbar links to access sections like "About" or "Services," I get a 404 error. Interestingly, when I place the controller for "Services" or "About" in the route of the homepage, the page displays correctly.
Any help would be greatly appreciated

I’ve checked the following:

Controllers and views are in the appropriate directories.

My routes are correctly defined in the web.php file.

I’m using the route() function to generate URLs.

2

Answers


  1. Chosen as BEST ANSWER

    Hello @Herrys Aghista Rachman , I wanted to express my sincere gratitude for your response on Stack Overflow regarding my issue with accessing pages in my Laravel application outside of using artisan serve. I followed your advice and tried various approaches, including adding "public" to the routes, modifying the "index.php" file, and creating a "myapp" folder in the root directory of my domain. To provide more context, I have also made modifications to the "index.php" file as follows:

    <?php
    
    use IlluminateContractsHttpKernel;
    use IlluminateHttpRequest;
    
    define('LARAVEL_START', microtime(true));
    
    /*
    |--------------------------------------------------------------------------
    | Check If The Application Is Under Maintenance
    |--------------------------------------------------------------------------
    |
    | If the application is in maintenance / demo mode via the "down" command
    | we will load this file so that any pre-rendered content can be shown
    | instead of starting the framework, which could cause an exception.
    |
    */
    
    if (file_exists($maintenance = __DIR__.'/myapp/storage/framework/maintenance.php')) {
        require $maintenance;
    }
    
    /*
    |--------------------------------------------------------------------------
    | Register The Auto Loader
    |--------------------------------------------------------------------------
    |
    | Composer provides a convenient, automatically generated class loader for
    | this application. We just need to utilize it! We'll simply require it
    | into the script here so we don't need to manually load our classes.
    |
    */
    
    require __DIR__.'/myapp/vendor/autoload.php';
    
    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request using
    | the application's HTTP kernel. Then, we will send the response back
    | to this client's browser, allowing them to enjoy our application.
    |
    */
    
    $app = require_once __DIR__.'/myapp/bootstrap/app.php';
    
    $kernel = $app->make(Kernel::class);
    
    $response = $kernel->handle(
        $request = Request::capture()
    )->send();
    
    $kernel->terminate($request, $response);
    
    

    I followed these steps meticulously, including creating a "myapp" folder in the domain directory, placing the "index.php" and ".htaccess" files in the root directory of the domain, and modifying the "index.php" file as shown above. However, despite these efforts, the problem persists. The application still only accesses the homepage, and the other routes do not work correctly.

    To clarify, when hovering over a button like "Service" or "About," the correct route is displayed. However, upon clicking these links, the application does not navigate to the expected pages.

    If you have any further ideas or suggestions to resolve this problem, especially considering the "myapp" folder and index.php modification, I would be grateful for any additional assistance.

    Once again, thank you for your invaluable help.


  2. when you run locally, its served and root dir is in public, but if you dont artisan serve it, it need to add root_dir"/public/"your_routes to access it

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