Solution - Laravel How to Remove /public from url
Laravel is a most popular PHP framework and today we will solve most common issue with laravel by removing /public from URL. This code is tested with Laravel 8(Latest) but it will work with Laravel 7, 5 version also.
ISSUE
When we move our site on live server and do not run our application through terminal and try to access website by entering url then we need to add /public to run it successfully, But its not good to keep /public in our website url that will not seo friendly and creates bad user experience.
SOLUTION FOR LARAVEL REMOVE PUBLIC FROM URL
Create a .htaccess file on your root directory and paste below code into .htaccess file and save it.
try this code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
or this one
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
Now run your website without entering public in the url and it will work. :)
Related Links
How to remove public from url
.htaccess for remove public from laravel application
Comments
Post a Comment