Мне нужна конкретная конфигурация для одного из моих виртуальных серверов, но у меня проблемы с объяснением этого Nginx :)
Это довольно просто. Если URI выглядит как
example.com/whatever_1/whatever_2/.../whatever_n
Я бы хотел его переписать как
example.com/index.php?request=whatever_1/whatever_2/.../whatever_n
Второй - если URI начинается с /administration/
лайк
example.com/administration/whatever_1/.../whatever_n
Я бы хотел, чтобы это было переписано как
example.com/administration/index.php?request=whatever_1/.../whatever_n
Я возился и пробовал:
server
{
# listen 80;
server_name example.com;
index index.html index.php;
root /srv/example/;
location ~ /administration/(.*)$
{
if (!-e $request_filename)
{
rewrite ^/(.*)$ /administration/index.php?request=$1 last;
}
break; #tried with and without it
}
location / #tried with and without this location block
{
if (!-e $request_filename)
{
#rewrite ^/(.*)$ /index.php?/$1 last;
rewrite ^/(.*)$ /index.php?request=$1 last;
}
}
location ~ \.php$ #boilerplate
{
# Filter out arbitrary code execution
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
Но это не работает. Я новичок в Nginx, поэтому любая помощь будет оценена.
Спасибо, Янв.
Это nginx, а не apache. По возможности следует избегать перезаписи (а это часто возможно).
Использовать try_files
вместо. Например:
location /administration/ {
try_files $uri $uri/ /administration/index.php?request=$request_uri;
}
location / {
try_files $uri $uri/ /index.php?request=$request_uri;
}