Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

argethink's avatar

How to remove /public/ from a Laravel 10

I want to remove the /public/ fragment from my Laravel 10 URLs.

I have tried several things regarding public.

1- I have changed the .htaccess. Yes it worked.

domain.com/public/contact : it is valid

domain.com/contact : it is valid

But i have another problem, google thinks i have duplicate pages.

2- Then, i have tried to another way, I changed the root of website as public.

Everything was worked.

But when i open the url domain.com/public i got error. Too many redirections. It automatically downloaded a file. it's name is public without extention.

At the end, i want to remove public segment from the url. When i enter the domain.com/public/contact, i should get 404 error. :tired_face:

Can you help me solve this problem , thank you in advance. .env

APP_URL=https:// domain.com

#public .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    RewriteEngine On
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
     # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
0 likes
22 replies
vincent15000's avatar

What APP_URL value have you written in the .env file ?

1 like
kokoshneta's avatar

@argethink /public should not be part of your app URL. The app URL is the domain name that you’re expected to type in the browser’s address field to access the site’s homepage.

2 likes
argethink's avatar

@kokoshneta I have tried both way. (APP_URL= domain.com/public and APP_URL= domain.com) . The results were same.

1 like
argethink's avatar

@vincent15000 I wrote it without https:// Because i signup today and laracast didnt allow me to write a link. APP_URL : https:// domain.com

1 like
vincent15000's avatar
Level 63

@argethink Ok ... no problem ... so first you should modify the APP_URL to set it with the right value.

Concerning the .htaccess file, here is the one I'm using (try to add the RewriteBase line).

<IfModule mod_rewrite.c>

    RewriteBase /

    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
</IfModule>
1 like
argethink's avatar

@vincent15000 Thank you, i updated the .htaccess file as you mentioned. But i am still getting same error in https:// domain.com/public The error is too many redirections. It automatically downloaded a file. it's name is public without extention.

1 like
vincent15000's avatar

@argethink That's strange.

In the webhosting configuration to use your domain name, you have to point the domain to the public folder of the Laravel application.

Is it the case ?

1 like
argethink's avatar

@vincent15000 I have plesk panel and i only changed the document root to the public. Yes the case is correct.

1 like
kokoshneta's avatar

@argethink But if you have Plesk and access to changing the document root… why do you need the .htaccess?

You’ve done something very wrong somewhere, because if you have access to the document root’s parent folder and deploy your app into it, then the URLs will not contain /public. You don’t need to mess around with .htaccess files or anything else for that to work.

2 likes
argethink's avatar

@kokoshneta I have tried to solve this, firstly i changed the httacess in document root. In this case i had duplicate pages such as domain.com/contact and domain.com/public/contact . Google didnt like the duplicate page. Then i have tried to change the document root to the public. In this case i didnt change .htaccess Everything worked properly. But when i go to domain.com/public, i am getting error.

1 like
kokoshneta's avatar

@argethink You should not need to change anything in your server’s .htaccess file for Laravel to work.

Please show us the folder structure on your server where your app is located, and which directory in that structure is the document root, because something is very wrong in your setup.

2 likes
argethink's avatar

@kokoshneta document root

app
bootstrap
config
database
public
resources
routes
storage
tests
vendor
.htaccess # it is for only first case
.env
composer.json
...
and other files related to laravel.

public root

.htaccess
index.php
robots.txt
1 like
kokoshneta's avatar

@argethink Well, that shows your mistake.

The document root (i.e., the directory whose contents the server outputs if you go to domain.com) should be the public directory. Everything else in your Laravel app should be outside the document root.

There is no such thing as ‘public root’. public is just the name of a folder, nothing more – but it’s the folder that should be the document root. So let’s say your website is located inside /var/www on the server, your structure should look like this:

/var/www/app
		 bootstrap
		 config
		 database
		 public  <-- this is the server’s document root
		   index.php
		   robots.txt
		 resources
		 routes
		 storage
		 tests
		 vendor
		 .env
		 composer.json

Since you say you have access to Plesk and can change the document root for the site, you should set it to /var/www/public in the above example (using the absolute path to the public folder on the server).

2 likes
argethink's avatar

@kokoshneta @vincent15000 Thank you for your clarification, I am really appreciate you. I have found my mistake. I checked the browser cache then i deleted browser cache. After the deletion, the second case work perfectly.

1 like
Snapey's avatar

@argethink if you expose the root laravel project, (containing the public folder), you also risk exposing .env and storage log files.

You should take advice seriously and set your web server to serve the public folder as its document root, making everything else unreachable, and restore your .htaccess file back to the default. Finally set app_url to be your bare domain name.

2 likes

Please or to participate in this conversation.