Apr 24, 2012

.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]

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?

Asked by harvest316


.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).

Answered by pjmorse

Related posts:

  1. .htaccess question – document root – Do we need this RewriteRule in here?
  2. .htaccess RewriteRule not working with root ‘/’
  3. Multiple levels of .htaccess files with RewriteRule, only deepest level processed
  4. Prevent loop of RewriteRule in .htaccess
  5. .htaccess redirect works for IP, but not for domain name

Leave a comment