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
-
Open your browser and go to
yourdomain.com/cpanel -
Log in with your cPanel username and password
-
Once logged in, look for File Manager
Step 2: Open the File Manager
-
Click File Manager
-
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.
-
On the top right, click Settings
-
Check the box Show Hidden Files (dotfiles)
-
Click Save
Step 4: Locate and Edit Your .htaccess File
-
Find the
.htaccessfile inside your project folder -
Right-click it and select Edit or Code Edit
-
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>
-
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:
-
Go to
bootstrap/cache/in File Manager -
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
/publicfolder
3. Routes Not Working
-
Confirm you edited the correct
.htaccessfile -
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.
Tanzania
Kenya
Uganda
Rwanda
South Sudan
Nigeria
Ghana
South Africa
Zambia
India
United Kingdom
Global Route Africa