[Laravel] localhost / project name / public ← How to eliminate public

Sep 8, 2020 PHP Laravel

After investigating, there are several methods, but I thought it was the smartest method, so I will leave it as a memo.

Create ## .htaccess

.htaccess is one of the hidden files that describes settings such as redirects.

Copy the following description there.

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

Reference: https://gist.github.com/liaotzukai/8e61a3f6dd82c267e05270b505eb6d5a

Paste the code with vscode etc. and save it in the root directory of Laravel.

Even if you save it, it is a hidden file, so it is not displayed in the folder. If you want to display hidden files, use that folder (For mac)

command + shift +. (dot)

You can display it by entering.

that’s all! You can move to the root directory with localhost / project name.