.htaccess RewriteRule works on addon domain but not root domain
I made a .htaccess in an addon domain, which successfully hides the wp-admin folder:
# Hide wp-admin
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !MagicString
RewriteRule ^wp-admin/.*$ - [R=404,L]
</ifModule>
Now I’d like to move this to the root domain’s .htaccess so it hides all the wp-admin folders on all addon domains. But try as I may, it ain’t working. What am I doing wrong?
.htaccess rules only apply within scope. If someone makes a request to a.example.com and the .htaccess file for example.com is not inside the document tree of a.example.com, that file won’t be read or respected. If the vhosts serving a.example.com and example.com aren’t the same, you’ll need to apply that rule to each vhost separately.
You may be able to apply rewrite rules across multiple subdomains if they use the same vhost (put the rule in the vhost definition block, which is more efficient than using .htaccess).
Check more discussion of this question.
Related posts:
- .htaccess question – document root – Do we need this RewriteRule in here?
- .htaccess RewriteRule not working with root ‘/’
- Multiple levels of .htaccess files with RewriteRule, only deepest level processed
- Prevent loop of RewriteRule in .htaccess
- .htaccess redirect works for IP, but not for domain name
Leave a comment
Recent Posts
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
- Is there research material on NTP accuracy available?
- How to create a limited “domain admin” that does not have access to domain controllers?





