'Laravel 7.x - How to remove 'public' from URL?

Stuck with this for a long time. I found similar questions but none of the answers are working for me! .htaccess in root folder looks like this:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public/ 
RewriteRule ^(.*)$ /public/$1 [L,QSA]


Solution 1:[1]

Create a file named as '.htaccess' in root and add the below code. That's it

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

Solution 2:[2]

The example here is in the /public directory. You will also need to configure you're server correctly and have it look only at the /public directory instead of root. You shouldn't need an .htaccess file in the root.

You will need a httpd-vhosts.conf with something like the following:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName yourapp.com
    ServiceAlias www.yourapp.com
    DocumentRoot /var/www/yourapp/public
</VirtualHost>

Notice this line:

DocumentRoot /var/www/yourapp/public

You can read more about Laravel webserver configuration here.

Solution 3:[3]

inside of your main .htaccess it should read:

<IfModule mod_rewrite.c>
   RewriteEngine on     
   RewriteCond %{REQUEST_URI} !^public
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

replace the existing " RewriteRule ^(.*)$ public/$1 [L] " if something like this exist.

Solution 4:[4]

below solution worked for me.

Create .htaccess file in root directory and place code something like below. copy server.php file and paste it in root directory with named as index.php .

put below code in .htacess created file in root directory .

Options -MultiViews
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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nabin Rawat
Solution 2 Karl Hill
Solution 3 Brennan James
Solution 4 Ameer Safdar