参考链接: https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/

You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.

Why?

This is a great question. For starters, for .htaccess to work Apache needs to check EVERY directory in the requested path for the existence of a .htaccess file and if it exists it reads EVERY one of them and parses it. This happens for EVERY request. Remember that the second you change that file, it’s effective. This is because Apache reads it every time.

Numbers

http://example.com/site/files/images/layout/header.png

Let’s say we’re not doing any funky aliasing and the file system looks like the path. This covers most of the sites out there. There is the / directory, then site/, files/, images/, and layout/. This amounts to 5 directories that could have a .htaccess file. Let’s say you added a .htaccess in /, files/ and images/. That’s three .htaccess files. That’s pretty typical.

Now the numbers, that’s 6 file system stats and 4 file system reads. Including one for the requested file. This happens for every read. We’ll ignore parsing time because both NGINX and Apache need to do this and we’ll consider the difference in time for this negligible.