Here, we cover the basic Laravel .htaccess configuration. Without this, subpages may show a 404 error or the site may only load when visiting the public folder.
In a standard Laravel installation, the .htaccess file located in the Laravel project's root directory plays a crucial role in redirecting requests to the public folder. This redirection ensures that all incoming traffic is directed to the public folder, which serves as the entry point for the web application.
The .htaccess rules in this file typically include directives to rewrite URLs, allowing for a clean and organized URL structure while keeping the application's core files secure and hidden from direct access. This configuration enhances security and follows best practices for Laravel web applications.
Related Articles
Manually Install Laravel
View Laravel Error Logs
Configure Redirect
- Log into the cPanel
- Click on File Manager, located in the Files section
- Navigate to the site's document root
- Edit the .htaccess file
- Add the following
RewriteEngine on
TIP: If Laravel was installed in a subdirectory, the following .htaccess should be used instead.
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteEngine on
REPLACE: your_project_name with the subdirectory.
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ your_project_name/public/$1 [L] - Review the site
TIP: If this is a new install, a Laravel logo should be displayed along with some documentation links.
NOTE: If on an NGINX server, the NGINX cache may have to be cleared.
Comments
0 comments
Article is closed for comments.