Main laravel goes above htdocs. You should not need to mess around with htaccess file. Do a search right here myself and many others have answered how to properly set up laravel on shared hosting.
I know it's been answered over a hundred times.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
My website is running perfectly in www.mywebsite.com, but I notice people can enter in the URL:
www.mywebsite.com/public
www.mywebsite.com/public/index.php
www.mywebsite.com/server.php
And all links shows my website but without CSS applied. Is there any way I can redirect users to my main URL?
Btw, I use the /public/ folder for JS, CSS & Images, like such:
www.mywebsite.com/public/img/somefile.png
www.mywebsite.com/public/js/somefile.js
www.mywebsite.com/public/css/somefile.css
And I want to maintain that.
This is my root .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Remove www
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ https://mywebsite.com [R=301,L]
# Remove http and force https
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^ [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
And this is my 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Finally, I'm using a shared hosting.
Thanks.
Please or to participate in this conversation.