Answer the question
In order to leave comments, you need to log in
How to do location/rewrite correctly?
server {
listen 80;
listen [::]:80;
server_name site.ru;
root /var/www/site.ru;
index index.html;
location ~* \.(?:jpg|jpeg|gif|png|webp)$ {
expires 30d;
}
location ~* \.(css|js|woff2)$ {
expires 30d;
}
location / {
try_files $uri $uri/ =404;
}
rewrite ^/([a-z,0-9,-]+)$ /pages/$1.html last;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/javascript application/javascript application/x-javascript text/xml application/xml application/xml+rss application/json;
gzip_disable "msie6";
}
Answer the question
In order to leave comments, you need to log in
If there are no special differences in the names of ordinary and those that are divided into several pages.
Then it remains to sequentially check the existence of files.
location / {
try_files $uri $uri/ =404;
}
rewrite ^/([a-z,0-9,-]+)$ /pages/$1.html last;
location / {
try_files $uri $uri/ /pages$uri-$arg_p.html /pages$uri-1.html /pages$uri.html =404;
}
rewrite ^/([a-z0-9-]+)$ /pages/$1-$arg_p.html last;
location ~ ^(/pages/.+)-\.html$ {
internal;
try_files $1-1.html $1.html =404;
}
location ~ ^/pages/.+\.html$ {
internal;
try_files $uri =404;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question