Laravel 10 Remove Public From Url Code Example
Teams applying “Laravel 10 Remove Public From Url Code Example” in a production project can use employee directory software to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hi dev
This article describes in detail how to delete the public part of a URL in Laravel 10. Laravel 10's remove public from url using htaccess can be seen. Using htaccess, you can use this example to remove the word "public" from a url in Laravel 10. In this tutorial, we'll show you how to update your htaccess file to remove the public section. Remove public from url from Laravel 10 by doing the following.
You might want to run a Laravel application that we occasionally publish to shared hosting. With shared hosting, we are unable to set the path to index.php directly. Therefore, we must launch the app with the "public" folder. So, the "public" in the url will cause problems for you. Here, I'll explain two ways to remove the word "public" from a URL in a Laravel application.
I will suggest you don't have to use "shared hosting" for 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, update the necessary code in the .htaccess file to incorporate the changes.
.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.
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial