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

keevitaja's avatar

How to remove first uri segment in .htaccess

EDIT: Cannot be solved with .htaccess ! REQUEST_URI is not changed by any rewrite!

Hello,

i need to write a .htaccess rewrite rules that removes the first uri segment in Laravels public/.htaccess file.

/foo/bar/baz has to become /bar/baz

I haved gooled araund with no luck. So please don't copy/paste anything from stack overflow unless you know it is working :) thank you so much!

Do you have a solution?

0 likes
1 reply
Tray2's avatar

I'm guessing you are using a shared hosting service and you want to change htts://mysite.com/public to https://mysite.com.

I use the following .htaccess in my root folder and not the public folder to achive that.

#Rewrite everything to subfolder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public
Rewriterule ^(.*)$ public/ [L]

Please or to participate in this conversation.