I am working on laravel 5.4 project and want to remove public from url.Right now my url is localhost/project_name/public/login. Please suggest me way remove public from url.
2 Answers
Step 1: Rename File
In first step it is very easy and you need to just rename file name. you have to rename server.php to index.php at your laravel root directory.
server.php INTO index.php Step 2: Update .htaccess
first of all you have to copy .htaccess file and put it laravel root folder. You just copy .htaccess file from public folder and then update bellow code:
.htaccess
Options -MultiViews -Indexes RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/public/ RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC] Documentation : https://hdtuto.com/article/laravel-remove-public-from-url-using-htaccess
2 Comments
Asim Malik
i have less than 15 reputition, vote cast but not public. Thanks
elysian-design
thanks a lot... i've tinkered around for about 8 hours by now, following different tuts. Your solution is the first one, working completely as I want!
Create a new .htaccess file in your root and paste following code.
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 ONE OF THE BEST SOLUTION