I'm using NGINX to run a wordpress membership site, where I need to restrict access to specific files and memberships, but in order for this to work I must add the following rules to .htaccess:
RewriteCond %{REQUEST_URI} !^/(wp-content/themes|wp-content/plugins|wp-admin|wp-includes) RewriteCond %{REQUEST_URI} \.(mp3|mp4|avi|pdf|zip|rar|doc|gz|tar|docx|xls|xlsx|PDF) RewriteRule . /index.php?ihc_action=check-file-permissions [L]
But of course .htaccess doesn't exist since I'm not using APACHE.
So I converted the .htaccess rules to nginx.conf directives:
location ~ \.(mp3|mp4|avi|pdf|zip|rar|doc|gz|tar|docx|xls|xlsx|PDF)$ { # Check if the URI does NOT start with the excluded paths if ($request_uri !~ ^/(wp-content/themes|wp-content/plugins|wp-admin|wp-includes)) { rewrite ^ /index.php?ihc_action=check-file-permissions last; } # If it does start with an excluded path, or if it doesn't match the file extensions # (though the location block already handles file extensions), # then let Nginx try to serve the file normally. # This try_files is a fallback for when the 'if' condition is false. try_files $uri $uri/ /index.php?$args; }
Unfortunately it doesn't work
Any ideas?
nginx -T
command. This configuration snippet alone isn't enough to find the reason.