Laravel – Remove Public from URL using htaccess
https://hdtuto.com/article/laravel-remove-public-from-url-using-htaccess
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]
Image Upload with Reset Button
<div class="form-row"> <div class="container"> <label class="ants-label-light" >Club Emblem</label> </div> <div class="input-group mb-6 container justify-content-center"> <div class="row"> <div class="col-6"> <form action="/uploads" method="post" enctype="multipart/form-data"> <label class="btn btn-ants"> <i class="fa fa-image"></i> Upload Club Emblem <input type="file" style="display: none;" name="club_emblem" id="imgInp"> </label> </form> </div> <div class="col-6"> <label class="btn btn-secondary file_reset"> <!-- Remove Image --> <i class="fa fa-undo"></i> </label> </div> </div> <div class="image-display-box"> <form runat="server"> <img class="upload_display" src="#" alt="Club Emblem" /> </form> </div> </div> </div>
$( document ).ready(function() { // /////////////////////////////////////////////////////////////////////////// function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('.upload_display').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); // convert to base64 string } } $("#imgInp").change(function() { readURL(this); }); $('.file_reset').on('click', function() { $('.upload_display').attr('src', ''); }); // /////////////////////////////////////////////////////////////////////////// });
Javascript Prevent Page Hot Reload
document.onkeydown = function() { switch (event.keyCode) { case 116 : //F5 button event.returnValue = false; event.keyCode = 0; return false; case 82 : //R button if (event.ctrlKey) { event.returnValue = false; event.keyCode = 0; return false; } } }
Laravel All Routes Returning 404
Replace your .htaccess file with the below solution contents
Solution:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule> # Set the “ea-php71” package as the default “PHP” programming language. <IfModule mime_module> AddType application/x-httpd-ea-php71 .php .php7 .phtml </IfModule>
Laravel New Project
use this one through composer:
composer create-project laravel/laravel
This is an older one I tried previously use the one above first:
composer create-project –prefer-dist laravel/laravel blog “5.8.*”
© Garth Baker 2025 All rights reserved.