Question

Laravel 10 project, doesn't work navigation

Deployed Laravel 10 project and it shows index page but when I click e.g. news, about us … it return 404. I check links in inspect and here I have http://ip-address/news, http://ip-address/about-us. How can I fix it? As chatGpt told me for the fix it should change permissions, I try it but doesn’t works


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
March 7, 2024

Hey!

Besides permissions as GPT suggested, this could be related to a few other things:

  1. Ensure that Apache’s mod_rewrite module is enabled. You can enable it by running the following command:

    sudo a2enmod rewrite
    

    After enabling, restart Apache to apply the changes:

    sudo systemctl restart apache2
    
  2. Laravel uses a .htaccess file in the public directory to rewrite URLs. Ensure the .htaccess file exists and is correctly configured. Here’s the default content for Laravel’s .htaccess file:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

    Ensure this file is present in your public directory.

  3. Check your Apache site configuration to allow overrides from the .htaccess file. Edit your site’s configuration file (usually located in /etc/apache2/sites-available/) and ensure the <Directory> directive for your site’s document root (usually the public directory of your Laravel project) looks like this:

    <Directory /var/www/html/your-laravel-project/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    Replace /var/www/html/your-laravel-project/public with the actual path to your project’s public directory.

  4. After making changes to the Apache configuration or the .htaccess file, restart Apache to apply the changes:

sudo systemctl restart apache2

Let me know how it goes! Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel