Answer the question
In order to leave comments, you need to log in
How to remove index, .php, .html from url if you have NGINX?
Colleagues, tell me how to painlessly move to nginx and get rid of extra index, .php, .html
server {
listen %ip%:%web_ssl_port%;
server_name %domain_idn%;
root %sdocroot%;
index index.php index.html index.htm;
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass %backend_lsnr%;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
Answer the question
In order to leave comments, you need to log in
location / {
# Удаляем index.html из всех уровней url
rewrite ^(/.*)/index.html $1 permanent;
# Удаляем .php
rewrite ^(/.*)\.php(\?.*)?$ $1$2 permanent;
# Удаляем .html
rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
# Удаляем закрывающий слэш
rewrite ^/(.*)/$ $1 permanent;
# Определяем порядок файлов для обработки запроса
try_files $uri/index.php $uri.php $uri/index.html $uri.html $uri/ $uri =404;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question