A
A
ArrayPop2020-10-02 10:54:41
Nginx
ArrayPop, 2020-10-02 10:54:41

How to make a 404 page when requesting txt,html file extensions in the address bar on wordpress + nginx? And how to set dynamic robots.txt?

1) When requesting a directory, for example, localhost/folder or localhost/folder , the correct 404.php page from wordpress is given. But when I try to write localhost/folder.txt or folder.html like this, I get a 404 page from nginx. I know that something needs to be registered in the nginx config, but I don’t know what.
2) How to set up dynamic robots.txt in WordPress, again, due to the fact that txt files are processed by nginx, it is impossible to make virtual robots.txt, something needs to be written in the config. I would like to register such a config that in general will give all file extensions for processing by php if php starts working with one of these extensions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ArrayPop, 2020-10-02
@ArrayPop

Found a way

location ~* ^.+\.(.+)$ {
  try_files $uri $uri/ /index.php?$args;
  log_not_found off;
}

Any string from the beginning - ^.+
Dot symbol - \.
Any extension - (.+)
Give php for processing - try_files $uri $uri/ /index.php?$args;
Now if there are no files with any extension (html|css|zip|txt) we will send them to index.php.
Also 404 page can be configured in php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question