Estou tentando reescrever um URL como abaixo:
https://example.com/products/xperia-z5/ to--> https://example.com/xperia-z5/
Mas, ao mesmo tempo, quero que o url https://example.com/products/
seja acessível, sem modificações, já que é um catálogo de produtos.
Por motivos de organização, mantenho meus arquivos em / products / file1, file2 etc.
Talvez eu deveria estar usando "alias" e não "reescrever"?
Talvez eu deva alterar algo na diretiva try_files , ou algo está errado com o local @ extensionless-php , estou totalmente confuso.
Por favor, conselhos.
Obrigado.
Abaixo está minha configuração do server.conf
server {
server_name 192.168.10.1;
listen 80;
root /home/webmaster/example.com/html_public;
charset UTF-8;
# replace .php extension with trailing slash
location @extensionless-php {
rewrite ^(.*)/$ $1.php last;
rewrite ^(.*[^/])$ $1/ permanent;
}
location / {
try_files $uri $uri/ @extensionless-php;
}
error_page 404 /404.php;
#pass the PHP scripts to FastCGI server listening on php-fpm unix socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location /products/$ {
rewrite ^/products/(.*)$ /$1 break;
}
}
Quando tento solicitar o link nos registros que eu estou recebendo (com 404):
2016/04/25 16:50:19 [notice] 10191#0: *1 "^(.*)/$" matches "/xperia-z5/", client: 192.168.10.2, server: 192.168.10.1, request: "GET /xperia-z5/ HTTP/1.1", host: "192.168.10.1"
2016/04/25 16:50:19 [notice] 10191#0: *1 "^(.*)/$" matches "/xperia-z5/", client: 192.168.10.2, server: 192.168.10.1, request: "GET /xperia-z5/ HTTP/1.1", host: "192.168.10.1"
2016/04/25 16:50:19 [notice] 10191#0: *1 rewritten data: "/xperia-z5.php", args: "", client: 192.168.10.2, server: 192.168.10.1, request: "GET /xperia-z5/ HTTP/1.1", host: "192.168.10.1"
2016/04/25 16:50:19 [notice] 10191#0: *1 rewritten data: "/xperia-z5.php", args: "", client: 192.168.10.2, server: 192.168.10.1, request: "GET /xperia-z5/ HTTP/1.1", host: "192.168.10.1"
2016/04/25 16:50:19 [info] 10191#0: *1 recv() failed (104: Connection reset by peer), client: 192.168.10.2, server: 192.168.10.1, request: "GET /xperia-z5/ HTTP/1.1", host: "192.168.10.1"