I want to configure nginx so that all requests that start from the "/ usa" folder lead to a specific index.php.

What you need: I want to place the site in a folder of another site so that one site can be accessed at site.com/usa , and another site site.com be accessed at site.com . Both sites should accept all requests to their index.php.

When I address on url site.com/usa/test , returns the 404th error that there is no such urla. In principle, it is logical, since it should be redirected to site.com/usa/ , but I do not know how to do it.

Config file contents:

 server { listen 80; listen [::]:80; root /var/www/site.com; index index.php index.html index.htm; server_name site.com; charset utf-8; location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css|woff|otf|eot|fft)$ { expires max; } location / { rewrite ^([^.]*[^/])$ $1/ permanent; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } } 
  • so what exactly is your problem? what works "wrong"? - aleksandr barakin
  • When I address urla site.com/usa/test, it throws a 404 error that there is no such url (basically logical), since it should be redirected to site.com/usa/, but I do not know how to do it - PendalF
  • Please add this information to the question. and at the same time bring the current contents of the server section. Corrections can be made by clicking below the text of the question - aleksandr barakin

1 answer 1

try adding one more section:

 location /usa { try_files $uri $uri/ /usa/index.php?$args; }