php - Redirect url in laravel
one text
Solution:
Hi and welcome on StackOverflow.
To remove /public
from the url of your app you will need to edit the .htaccess
you provided and put it in the main folder of your Laravel project (i.e.: where lies .env
, composer.json
, etc.), assuming you placed all the code of your Laravel app in the main domain directory of your Hosting Service. The new .htaccess
will look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# All other C-Panel related stuff
This will internally map all of your urls to /public
directory hiding /public
in browser.
Remember to not edit or delete the .htaccess
file inside the public
folder unless strictly necessary
You can try the code between <IfModule mod_rewrite.c>
and </IfModule>
with this online tool
I also suggest to install a local Apache Server (like XAMPP), try to setup a Virtual Host and play a bit with .htaccess
file to understand how to properly set up your Laravel Project in production.
Here's a guide on how to create a Virtual Host on XAMPP. It may be useful as a starting point to start creating one on your own.
Source