Restrict uploaded files into a custom folder to logged in users by htaccess: looking for Nginx – not only Apache – solution

Đã có trọn bộ đề thi thử THPT Quốc Gia 2022 các môn: vip.dethihsg247.com
QUẢNG CÁO: Đổi thẻ cào thành tiền mặt min rút 10k tại đây

Talking about this well known solution:

Github

Original discussion

I’m looking for a straightforward way working also on a Nginx installed WP and not only on Apache ones.

Is there any other code-based approach you would recommend, that
works fine on any server environment?

So far, after testing various plugins from the official repository on a Nginx installed WP website, I also discovered that a bunch of them just fail when the web server is not accepting htaccess rules.

In my opinion, the best would be using the same approach for both:

setting a htaccess / nginx web server rule controlling any file request made toward a specific /uploads subfolder. The rule I found working well on my Apache based WP is the following:

I found – almost – the same rule for a Nginx environment, but despite my tests I’m still not able to make it work on a subfolder, so the following is just for the whole /uploads folder, not recommended:

Furthermore, as long as many clients of mines have their installations on a shared hosting, asking the provider to set a nginx rule for a single website is a lost cause most of the times.

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com