Skip to content

Instantly share code, notes, and snippets.

@Guibzs
Last active March 26, 2023 15:17
Show Gist options
  • Star 45 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save Guibzs/a3e0b3ea4eb00c246cda66994defd8a4 to your computer and use it in GitHub Desktop.
Save Guibzs/a3e0b3ea4eb00c246cda66994defd8a4 to your computer and use it in GitHub Desktop.
Symfony 4 ~ .htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
@drondar
Copy link

drondar commented Feb 18, 2020

Hi @drondar, as you said, assuming that you are running an application with a front controller (index.php) in a folder '/public', all files which are intended to be 'public' (normally the front controller and all the assets: js, css and images) should live inside this folder.
So, since they are public, there's no reason to have restrictions on it.

If you want to protect the directory which contains the project (or business logic) like for example /src, you can put an .htaccess with a redirect to parent folder on each subfolder.

Here an example:

RewriteEngine On
RewriteRule ^(parent/). /$1 [R,L]

where 'parent' is the name of the parent folder.
You can replace R param with R=301 if you want to make it 'permanent' (but only when you are sure that it works).

Another option is working with folders' permissions if you are on Unix.

Hello, my situation is exactly what you are describing. Thank you very much, I'm going to try it right now.

@i3130002
Copy link

Worked on Symfony 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment