country map images

Choose your Country

Select your preferred Country with local selling and billing options

How to Update the Laravel .htaccess File in cPanel: Complete Guide by Route Africa Print

  • 0

How to Update the .htaccess File for a Laravel Project in cPanel

When hosting a Laravel project on a cPanel server, the .htaccess file is responsible for routing, URL rewriting, and ensuring your application loads correctly without showing /public in the URL.
This article explains how cPanel users can update the .htaccess file using the approved configuration.


Step 1: Access cPanel

  1. Open your browser and go to yourdomain.com/cpanel

  2. Log in with your cPanel username and password

  3. Once logged in, look for File Manager


Step 2: Open the File Manager

  1. Click File Manager

  2. Navigate to the directory where your Laravel project is hosted

    • Most users will be inside public_html/

    • If your project is in a subfolder, open that folder


Step 3: Enable Hidden Files (Dotfiles)

The .htaccess file is hidden by default.

  1. On the top right, click Settings

  2. Check the box Show Hidden Files (dotfiles)

  3. Click Save


Step 4: Locate and Edit Your .htaccess File

  1. Find the .htaccess file inside your project folder

  2. Right-click it and select Edit or Code Edit

  3. Remove any existing code and paste the approved Laravel configuration:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1 

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
</IfModule>
  1. Click Save Changes


Step 5: Clear Laravel Cache (Recommended)

If your hosting supports SSH, run the following commands:

php artisan config:clear
php artisan cache:clear
php artisan route:clear

If SSH is not available:

  1. Go to bootstrap/cache/ in File Manager

  2. Delete all files except:

    • packages.php

    • services.php


Step 6: Test Your Website

Visit your domain to confirm everything is working:

  • Routes load correctly

  • CSS/JS files load

  • No more “public” in the URL

  • No 404 or redirect loops

If everything loads normally, the .htaccess update is successful.


Common Issues

1. 500 Internal Server Error

  • Usually caused by missing mod_rewrite

  • Contact your hosting provider to enable it

2. CSS/JS Not Loading

  • Make sure assets are stored in the /public folder

3. Routes Not Working

  • Confirm you edited the correct .htaccess file

  • Ensure hidden files are enabled


Conclusion

Updating the .htaccess file is required for Laravel applications to work correctly on cPanel servers. By following the steps above, your Laravel project will support clean URLs, correct routing, and proper loading of public assets.

 


Was this answer helpful?
Back

Customer Support

Typically replies within minutes

Hi there 👋
If you have any questions concerning our products, simply click the button below to chat with us