0

I have N number of sites in WordPress multi-site. I want to restrict individual site login i.e.,

  • http://www.example.com/site1/wp-admin
  • http://www.example.com/site2/wp-admin

Only Network admin can access website/add content. i.e. only Network admin URL should be accessible: http://www.example.com/wp-admin. If possible all other login URLs should redirect to respective home pages. Is there any functions or .htaccess rule to achieve this?

.htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
1

You can try something like the following at the very top of your .htaccess file in the document root (before the WordPress front-controller, ie. before the # BEGIN WordPress block):

RewriteRule ^([\w-]+/)wp-admin /$1 [R,L]

This will redirect /<site>/wp-admin to /<site>/ - where the site name can consist of any of the characters a-z, A-Z, 0-9, _ and -.

http://www.example.com/wp-admin is accessible as normal.

Yes its working, if wordpress is in sub directory its not working.

If the WordPress .htaccess file is in a subdirectory then you will need to modify the directive like so:

RewriteRule ^wp-admin /subdirectory/ [R,L]

However, your setup is still unclear. Do you have multiple .htaccess files for different WordPress installs? A single multi-site .htaccess in a subdirectory and no other .htaccess files?

  • No effect in website. I placed this below the rules generated by default by WordPress when changed to multi-site – Manu K M Nov 19 '18 at 5:27
  • As I stated above, this must go "at the top of your .htaccess file". In other words before "the rules generated by default by WordPress". – MrWhite Nov 19 '18 at 9:38
  • Yes its working, if wordpress is in sub directory its not working. pls guide me <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /sub/ RewriteRule ^([\w-]+/)wp-admin /$1 [R,L] RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] </IfModule> – Manu K M Nov 20 '18 at 14:52
  • Are you saying the WordPress multi-site .htaccess file (front controller) is itself in a subdirectory and all subsites are in an additional sub-subdirectory? – MrWhite Nov 20 '18 at 16:29
  • No. Only multi-site site itself in sub directory – Manu K M Nov 21 '18 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.