I have app and public folders in my project. I want paths that starts with (css|im|js|lib)/ to be redirected to public folder, and anything else - to index.php file.
For example, http://mysite.com/css/s.css should be redirected to SITE_ROOT/public/css/s.css and http://mysite.com/absde should be redirected to SITE_ROOT/index.php
Here's working config for nginx:
server {
listen 80;
server_name mysite.com;
root /home/mysite/html;
location ~ \/(css|im|js|lib)\/ {
root /home/mysite/html/public;
expires 30;
try_files $uri =404;
}
location {
rewrite ^(.*)$ /index.php break;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Now I try to rewrite this for apache, I write something like that in .htaccess:
RewriteEngine On
RewriteRule ^(css|im|js|lib)\/(.*)$ public/$1/$2 [L]
RewriteRule . index.php [L]
This does not work. It seems RewriteRule . index.php applies before the second line so that everything goes to index.php. But why?
Nothing changes if I change the third row to
RewriteRule ^(.*)$ index.php [L]
And that means that the type of equation doesn't affect on the order of rules.
And only if I remove ^ symbol from the regex in the second line, site starts working as expected. But I don't want to remove it! Now http://mysite.com/abcde/css/s.css rewrites to css/s.css, and it shouldn't be that way. Also the second line starts working if I remove the third one (that means it's correct by itself).
That's so stupid simple but I can't find a mistake in theese three rows. Please help.