The nginx equivalent of
RewriteCond %{REQUEST_URI} ^.*wp-content/uploads/restricted/.*
RewriteRule ^wp-content/uploads/(restricted/.*)$ dl.php?file=$1 [QSA,L]
will be the
location ~ ^/wp-content/uploads/(?<file>restricted/.*) {
rewrite ^ /dl.php?file=$file last;
}
If you want to apply this to several folders under /wp-content/uploads
, use
location ~ ^/wp-content/uploads/(?<file>(?:restricted1|restricted2|restricted3)/.*) {
rewrite ^ /dl.php?file=$file last;
}
I don’t think there can be any other solution for nginx but to alter its configuration, after all the fact it has all the rules compiled at the startup instead of checking every single folder for .htaccess
on every request is one of the reasons that it so outperforms Apache.
Related Posts:
- How can I use an .htaccess file in Nginx?
- Why “Settings->Permalinks” creates .htaccess file on nginx server?
- Rewrite /?rest_route=/ link to /wp-json/ without changing default permalink structure in apache
- index.php not loading in main folder of wordpress
- WordPress site displaying 404 for any page apart from index
- Giving WordPress its own subdirectory – nginx
- Create subdomain masking for each user in WordPress
- Redirect from different port to subdomain – htaccess
- WordPress 404 on Subdomain
- Only expose routes with prefix /wp-json on WordPress using Apache
- What’s the opposite of required valid user in .htaccess authentication
- How can i redirect one url to another url using .htaccess or add_rewrite_rule
- Override htacces rule only for specific directory
- How do I test to ensure that my wp-config file is protected?
- .htaccess Security Header Rules
- mod_rewrite loop, redirecting http to https on certain section of wordpress blog
- .htaccess in subdir gets ignored by WordPress’ own .htaccess in /
- Directing subdomain to main domain and keeping the subdomain format with .htaccess
- WordPress – Promoting A Dev Build In A Subdirectory To Production / Root Directory
- how to combine wordpress htaccess on my root domain + php on subfolder
- Redirect old domain with query paramaters
- Does WP suppresses .htaccess if permalinks are disabled?
- Moving wordpress to different url/server creates redirect loop
- fix 302 redirection error on https
- Access sub-domain when root public_html is protected with .htaccess password
- Accepting special characters in querystring
- WordPress permalinks confusion
- Configure .htaccess to have a WordPress single site installation with all subdomains pointing to the same pages?
- Unable leverage Browser Caching on AWS Bitnami stack (Apache) through W3TC and Cloudfront CDN
- How to move wordpress website from hosting account to localhost
- How to block wordpress admin by htaccess
- I can access subdirectory, but not files within it
- Restrict download files from not generated Urls
- Enable webp support Nginx+Apache reverse proxy with moss.sh [closed]
- WordPress redirection
- How To Add CSP frame ancestors in WordPress Website? [closed]
- Subfolder install not working
- Browser Caching .htaccess
- Https to http redirect using htaccess
- Improve wordpress security by hiding non public resources
- htaccess rewrite conflict with wordpress rules and ssl
- Serve apache 404 for missing assets rather then wp 404 template WP_Rewrites
- Remove year and month in URL using .htaccess
- Nginx rules for subdomain multisite install (Bedrock)
- Unable to access WP admin
- Move wordpress to folder without changing urls
- Using WordPress only for the backend, and using AngularJS as a frontend
- Two domains on one WordPress Installation
- Protect Upload Folder Files With Ampersand Problem
- .htaccess and WordPress Admin Bar
- Blocking access to wp-login via htaccess not working
- How to Redirect huge numbers of URLs to another URLs?
- Struggling with add_rewrite_rule
- Cannot mask WordPress page URL using .htaccess
- How can I make an htaccess file on a Mac? [closed]
- 404 with post name permalinks
- Restricting user login by IP address
- WordPress overrides custom 404 page with it’s own
- Which is better: 301 Redirect in my .htaccess file or a plugin like Redirection?
- New installation can’t be found due to htaccess of the original non-WordPress site
- Fixing custom 404 pages broken by WordPress in a subdirectory
- I can’t access the admin panel links as I click it shows 403 error
- Https Redirect infinite loop in Mobile browsers
- How to hide login form if basic authentication fails?
- How can I set Cache TTL for woff and woff2 font files with htaccess?
- .htaccess RewriteRule always overwritten – how to prevent?
- What might be removing my redirects from my htaccess?
- WordPress .htaccess to consider blog as directory
- Disable directory browsing of uploads folder
- Redirect – remove custom query string
- Limit file downloads to logged in users (WP + Nginx)
- Password protect directory but not files
- main-domain of wordpress keep redirecting to subdomain
- How to deny access to a particular wordpress site url
- How do i allow access to a single file in my root directory? [closed]
- Rewrite URL in address bar for a specific page [closed]
- Home links redirects to old site
- Rewriting subfolders to specific parent folder in WordPress
- Azure WordPress deny access to xmlrpc
- domain redirection is not working from old to new
- Deny,Allow on .htaccess isn’t working
- Using htaccess to prevent spam through wp-comments-post.php
- Install second wordpress in root subfolder, Error 404
- URL Rewrite 404
- Remove subdirectory from links
- modifying htaccess for localhost with a custom port
- Nginx rules for subdomain multisite install (Bedrock)
- .htaccess redirects for posts in new directory and new domain
- domain.in/wp-admin give the result to 403 Access to this resource on the server is denied!
- insert_with_markers() WordPress & htaccess help
- Restrict Content for only Contributors via .htaccess
- Redirect from domain.com to subdomain.domain.com
- MAMP.app & .htaccess – Can’t override after config
- register_post_type and register taxonomy and htaccess
- Why ‘Authorization Required’ is coming on wordpress login
- Restricting direct downloads of wp content files, but allow them on the website.
- Forward blog requests to another URL
- .htaccess rewrite rule stopped working for wordpress site after moving server
- Home page returns 404
- Serve static files via a subdomain on a wordpress