Home  >  Q&A  >  body text

nginx - After blocking access to all txt files in WordPress, how to allow access to virtual robots.txt?

Introduction:
WordPress under Nginx
Nginx is set to prohibit access to all txt (method)
If you use a real robots.txt file, the above method is effective, but the website uses WordPress. A virtual robots.txt file is used. The above method causes the virtual robots.txt to be inaccessible.

How to set up nginx so that the virtual robots.txt file can be accessed?

or
Limit the path of the txt file with restricted access to the following 2 directories.
WordPress plug-in directory (/wp-content/plugins)
WordPress theme directory (/wp-content/themes).

PHP中文网PHP中文网2714 days ago621

reply all(3)I'll reply

  • 为情所困

    为情所困2017-05-16 17:11:44

    Pay attention to the order

    location = /robots.txt {
      rewrite ^/robots\.txt$ /index.php?robots=1 last;
      allow all;
    }

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:11:44

    You can just allow nginx for robots.txt separately and put it above the nginx rule that prohibits all txt

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 17:11:44

    @南小鸟 invited to answer

    reply
    0
  • Cancelreply