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

ganganimaulik's avatar

Is it safe to redirect to public folder with htaccess

<IfModule mod_rewrite.c>
   RewriteEngine On
   # Force SSL
   RewriteCond %{HTTPS} !=on
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # Remove public folder form URL
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

I plan use this htaccess on my server to remove public/ from url. is it a good idea?

0 likes
1 reply
LiamHammett's avatar
Level 18

It's not a good idea. If there's ever a configuration error or your .htaccess file gets deleted or not recognised, people will have access to your entire website (including your .env files). This is a very bad habit and you should avoid it, instead changing the path in your sites-available .confd files in Apache.

1 like

Please or to participate in this conversation.