Option 1: Use .htaccess
If it isn’t already there, create an .htaccess file in the Laravel root directory. Create a
Edit the .htaccess file so that it contains the following code:
Now you should be able to access the website without the “/public/index.php/” part.
Next, move everything out of the public directory and into the root folder. It should result in something somewhat similar to this:
After that, all we have to do is edit the locations in the
In
And change them to:
In
And change them to:
.htaccess
file your Laravel root directory if it does not exists already. (Normally it is under your public_html
folder)Edit the .htaccess file so that it contains the following code:
Option 2 : Move things in the ‘/public’ directory to the root directory
Make a new folder in your root directory and move all the files and folder except public folder. You can call it anything you want. I’ll use “laravel_code”.Next, move everything out of the public directory and into the root folder. It should result in something somewhat similar to this:
After that, all we have to do is edit the locations in the
laravel_code/bootstrap/paths.php
file and the index.php
file.In
laravel_code/bootstrap/paths.php
find the following line of code:index.php
, find these lines:
There are actually two methods to remove public from URL. One is which you have already mentioned that includes editing htaccess file to add rewrite rules (https://www.cloudways.com/blog/stay-away-from-laravel-shared-hosting/ ). The other method includes editing index.php file.
ReplyDelete