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

urwxgrwx's avatar

How to remove public from url in laravel 9

hi i am working with laravel 9 and i uploaded my project to a server. i am using cpanel my project files are in public_html. now xyz.com/public/xxx and xyz.com/xx reach the same address as if all my routes have been copied on the server.

0 likes
3 replies
jlrdw's avatar

Point to public as document root. Many past discussions on this.

urwxgrwx's avatar

@jlrdw I've seen other discussions but I don't understand what to do.can you explain how to do it?

jlrdw's avatar

@urwxgrwx I am guessing linux and apache:

https://www.tutorialspoint.com/how-to-setup-virtual-hosts-with-apache-web-server-on-linux

Or you leave the htaccess file alone in public and add a second to root with:

RewriteEngine On

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

@tray2 has one also, I don't have link, but a search will find it. But the virtual host is preferred.

If you use Nginx, the documentation fully covers that.

Edit:

See if your host has any tutorials on this, many do.

Please or to participate in this conversation.