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

Andreas94's avatar

Site reachable with both /public and without

Hi I have correctly configured laravel on my hosting, however the site is reachable both from:

https://hello.com
https://hello.com/public

making it then become the url:

https://hello.com/article/...
https://hello.com/public/article/...

How can I overcome this problem?

I tried with:

RewriteRule "^public\/(.+)" "https://hello.com/" [R,L]

but the redirect does not consider it...

0 likes
9 replies
bobbybouwmann's avatar

You need to point your webserver to the /public directory. If you used shared hosting most of the time the httpdocs directory is similar to this directory.

It's recommended to place everything from the public directory in the httpdocs directory and all the other stuff outside the httpdocs directory.

Andreas94's avatar

I discovered that this problem is created when a user tries to enter the site without http. If a user visits the site with http://hello.com he is referred to https://hello.com/public To force the use of https I used:

# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
jlrdw's avatar

By setting the framework up correctly which has been discussed well over two or three hundred times right on this forum. Have you tried to search yet?

GertjanRoke's avatar

@Andreas94 I tried this on a hosting where I was not able to point to the public folder by default and this worked for me

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/ [L]
Andreas94's avatar

@jlrdw I know very well that this topic can also be dealt with eight hundred times, I also searched on stackoverflow which have recommended different configuration... but the site works great for me, and the problem is only when a user visits the site without https that is brought to https://domain.ext/public/$1 instead of https://domain.ext/$1 but if one visits the site from https:// everything works fine

@GertjanRoke unfortunately if one enters from http it is routed to https with the public folder...

Andreas94's avatar

ok I found out that the culprit of everything was:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So now I miss it only to understand how to force the redirect 301 from http to https:

Reading many guides, they advise to put this in app\Providers\AppServiceProvider.php

    \URL::forceScheme('https');

But by doing so, I receive all the url of the page in HTTPS (css,js,image...), but the user continues to stay on an http page... How can I do?

Edit

I'm continuing to do some tests, inserting this

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://hello.com/ [R,L=301]

if I am in: http://hello.com/article/6423

he redirects me to:

https://hello.com/index.php

creating a problem even for assets:

  <link href="https://hello.com/public/index.php/inc/app.css" rel="stylesheet">

I have no idea how I can redirect from http to https...

Please or to participate in this conversation.