Уважаемые коллеги, прошу подсказать, как поправить данный конфиг, чтобы в URL-е избавиться от index.php
Если можно, то без if-ов
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.domainname.com domainname.com;
return 301 https://domainname.com$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name www.domainname.com;
ssl_certificate /etc/letsencrypt/live/domainname.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domainname.com/privkey.pem; # managed by Certbot
return 301 https://domainname.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domainname.com;
ssl_certificate /etc/letsencrypt/live/domainname.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domainname.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /var/www/domainname.com/www/public_html;
index index.php index.html;
charset UTF-8;
autoindex off;
error_page 403 =404;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm-domainname.com.sock;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\.ht {
deny all;
}
location ~* \.(jpg|jpeg|gif|png|ico|pdf|ppt|bmp|rtf|svg|otf|woff|woff2)$ {
expires max;
}
location ~* \.(js|css|txt)$ {
expires 3d;
}
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_disable "msie6";
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml application/json application/xml application/x-javascript application/javascript text/javascript text/json;
}
Сейчас сайт доступен по таким URL-ам:
https://domainname.com
https://domainname.com/index.php
Самоё распространенное решение, найденное мною на просторах сети
server {
....
rewrite ^/index.php/(.*) /$1 permanent;
....
}
Но в моём случае не помогает.