Remove Public From URL

In this guide you will know how to remove public from url.

To Remove public from url your server must have enabled the mod_rewrite. header to check whether it's enabled or not you can run following http://yourdomain.com/phpinfo and check according to screenshot

Go to Admin / Help and Support / Remove public click on remove public button.

Remove public only work on main domain or subdomain. It will not work on if you running script on subfolder.

Remove Public Manually.

Create a .htaccess file (if not created) on root and paste below code and try to run site without public.

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Remove public with Force HTTPS

To enable force https into your script your SSL must be configured properly. after that you can go to

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{HTTPS} !=on
	RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
	RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

For more detail read the article here👉: https://stackoverflow.com/questions/23837933/how-can-i-remove-public-index-php-in-the-url-generated-laravel

Hide or Denied Access .env

To Hide or Denied Access .env and create .htaccess file in the root folder and write the following code.

# Disable Directory listing
Options -Indexes
# block files which needs to be hidden, specify .example extension of the file
</FilesMatch "^\.env">
    Order allow,deny
    Deny from all
<//FilesMatch>

Last updated