<IfModule mod_rewrite.c>
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>
This .htaccess code performs the following tasks:
- Enables Rewrite Engine: Activates the Apache
mod_rewritemodule for URL rewriting. - Rewrites URLs to Public Directory: Directs all requests to the
publicdirectory, where Laravel’s front controller (index.php) resides. - Handles Front Controller: Forwards all requests that do not match an existing file or directory to Laravel’s front controller (
index.phporserver.php).
Make sure to place this .htaccess file in the root directory of your Laravel project. Additionally, ensure that your Apache server configuration allows the use of .htaccess files and has the mod_rewrite module enabled.