Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess block access to directory but allow access to files

I have such situation. I'm developing application in Zend Framework and htaccess pointing every request to index.php. If some file or directory exists on the request path then htaccess allow access to this files like css, js, images etc...

Now I have for example such link:

example.com/profile/martin-slicker-i231

With Zend Router it points to controller account and action viewprofile. I want to add some avatart for my users and I created directory in public folder (so the images would be accessible by the server like css and js). The directory is named "profile" and subdirectory in it is "martin-slicker-i231". All path is visible by server like that:

public/
  .htaccess
  index.php
  profile/
    martin-slicker-i231/
      avatar-small.jpg

The problem is when i point browser to example.com/profile/martin-slicker-i231 it points me to this directory not the controller and action. When I remove the folder with user then the flow go to the controller and action. How to configure .htaccess so the example.com/profile/martin-slicker-i231 will be pointing to controller and action but request to example.com/profile/martin-slicker-i231/avatar-small.jpg point to the file. Here is my .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Can somebody help?

like image 672
Marcin Avatar asked Oct 10 '22 15:10

Marcin


1 Answers

Just remove the portion that says that it should serve directories:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l 
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Now it will serve files (with size > 0) and symbolic links directly, but send directory references and other urls to your application

like image 155
PatrikAkerstrand Avatar answered Oct 14 '22 03:10

PatrikAkerstrand