I am using Laravel 5.2 in my shared hosting server. I would like to remove public from url without changing server.php to index.php in root directory as doing so .env and other files are publicly visible. My .htaccess look likes below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
</IfModule>
5
Answers
You need to point you domain to public folder from cpanel.
or
Move your .htaccess file from the /public directory to the root directory and replace it content with the following code:
The Best Solution for this will be pointing your apache document root to laravel’s public folder.
But as you said you are using shared hosting then that might not be possible for you.
Now to access laravel app without public in the url follow this question
Laravel 5 – Remove public from URL
Also, you are concerned about other folders like app, config etc to not be accessible from the browser. Therefore to do that you can place an
.htaccess
file with contents
Deny from all
in every folder that you want to block access from the browser.Create new
.htaccess file in root directory
and paste with the following code
In root folder make .htaccess file with:
This is the exact working solution i found. Solution is taken from here, answered by Pallav Nagar
Create .htaccess file in root directory and place code something like below.