I think that what I'm trying to acomplish is similar to question (https://serverfault.com/questions/232051/rewrite-a-subdirectory-to-root-on-nginx#=) but I'll try to explain it better
so what I'm trying to do it to have the root of the domain (example.com) rewrite to the example.com/curr folder, except when curr is already in the request
example1:
example.com/ should rewrite to example.com/curr/
leading to the index.php located in there, serving it up (using php5-fpm for php)
example2:
example.com/curr should just be passed along, to be able to serve up the files
example3:
example.com/app should also just go to it's directory
current code (not working, 500 ISE):
location / {
try_files $uri $uri/ v1/$uri/ /curr/index.php?q=$uri&$args;
}
#location ~* ^/([a-zA-Z0-9\-]+)$ {
# root /webroot/www/myfolder/;
# try_files /curr/$1;
#}
location ^~ /p/ {
rewrite ^/(.*)$ /curr/index.php?p=$1 last;
}
note: the last location here defines rewrite if a page is defined, this one works fine and should have a very similar syntax to what should work for the root dir
thanks for helping me out.
update:
I've since also tried
location / {
try_files @missing;
}
location /curr/{
try_files $uri $uri/;
}
location @missing {
rewrite ^ /curr/index.php?q=$request_uri&$args?;
}
according to the linked question something like this should work, but this just gives me the index page on root
Edit:
I want to do this because all my subdomain folders are in the web/ folder, and I don't want those in the main website folder. I like to have everything separate & still conveniently accessible from f.e. FTP
Edit2:
I've got it up to the point where everything works, except 'example.com', which still renders me a 500 error
Code:
location / { rewrite ^ /curr/$uri last; }
location = / { rewrite ^ /curr/ last; }
location ^~ /curr/ {
try_files $uri $uri/;
}
(please also note that using only location = / { rewrite ^ /curr/ last; }
it did render the homepage correctly (but not everything else))
Best Answer
How about:
Edit after discussion below:
I am not convinced this is the best way to achieve whatever it is you're trying to achieve, but I think it should answer your question.
try_files won't achieve what you want I don't think (and not at all in your example as it's sending you into an infinite loop), as if index.html existed in the root, it wouldn't redirect you to /curr/ it would load up the index.html in root.