Laravel 11 Remove Public from URL Example
Here, we will learn how to remove public from url using htaccess file in laravel 11 application.
Sometimes, we put our Laravel app on shared hosting and want to run it. But we can't set the path to index.php directly on shared hosting. We have to run the app with the "public" folder. This makes "public" show up in the URL, which we don't want. Here, I will give you two solutions to remove "public" from the URL in a Laravel app.
I will suggest you don't have to use "shared hosting" for the laravel application and never go for this solution.
Solution 1: Laravel Remove Public From URL using .htaccess
In Laravel, the .htaccess file can be generated and edited to incorporate new changes. The .htaccess file is located in the root directory, and its modification requires mod_rewrite to be enabled on your Apache server. It is mandatory to enable the rewrite module to implement these changes. Moreover, you need to activate .htaccess in Apache virtual host to use it in Laravel.
Finally, Just go to root folder and create .htaccess file and upload with following code
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Solution 2: Rename server.php and Move .htaccess File
To remove "public" from your Laravel URL, you need to complete the following two steps:
1. Rename the server.php file in your Laravel root folder to index.php.
2. Copy the .htaccess file located in the /public directory to your Laravel root folder.
3. All public folder css and js file move to root folder.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 11 Send SMS using Twilio Tutorial Example
- Laravel 11 Store Backup on Dropbox using Spatie Tutorial
- Laravel 11 Import Large CSV File into Database Example
- Laravel 11 Custom User Login and Registration Tutorial
- Laravel 11 Generate PDF and Send Email Tutorial
- Laravel 11 Install Tailwind CSS Step by Step
- Laravel 11 JQuery Load More Data on Scroll Example
- Laravel 11 Notification | Send Notification in Laravel 11
- Laravel 11 Custom Validation Error Message Example
- Laravel 11 User Roles and Permissions Tutorial
- Laravel 11 Livewire Wizard Multi Step Form Tutorial
- Laravel 11 Livewire Pagination Tutorial Example
- Laravel 11 Livewire Form Validation Example