0

main .htaccess

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /test/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>

# END WordPress

wp-content/uploads/ .htaccess

RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx|)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . - [R=403,L]
MrWhite
  • 12,647
  • 4
  • 29
  • 41
Ricky
  • 1
  • But... you shouldn't need to merge those two config files (which is why the second `.htaccess` file is in the subdirectory to begin with)? Why do you want to merge the two files? What are you hoping to achieve? Why is the question tagged `nginx`? – MrWhite Sep 12 '22 at 12:28
  • _Aside:_ The regex in the first `RewriteCond` directive is arguably in error - it's not actually doing anything. – MrWhite Sep 12 '22 at 12:37
  • @MrWhite Sir, I am trying to disable direct url access (for images, pdf) to my wordpress websites for non loggedin users, above code 'wp-content/uploads/ .htaccess' worked in apache (localhost), but when I am trying to upload the same in nginx (siteground), it's not working. – Ricky Sep 13 '22 at 03:44
  • "upload the same in nginx" - Nginx does not use `.htaccess` files (`.htaccess` is an Apache config file), so it's not simply a case of "merging" these files. Nginx uses an entirely different syntax and requires the directives to be placed directly in the server config (there is no equivalent _userland_ config file like `.htaccess` on an Nginx server). (The `Nginx` tag was hastily removed from the question as it looked out of place, but in fact that is the main focus of your question!) – MrWhite Sep 13 '22 at 10:08
  • For example, https://serverfault.com/questions/378755/convert-htaccess-to-nginx and https://serverfault.com/questions/998611/how-to-convert-htaccess-rules-into-nginx-rule – MrWhite Sep 13 '22 at 10:34
  • found your another reply here - https://wordpress.stackexchange.com/questions/281500/protecting-direct-access-to-pdf-and-zip-unless-user-logged-in-without-plugin/, it helped, thanks @MrWhite – Ricky Sep 14 '22 at 06:24

0 Answers0