I use WordPress Multisite... and BuddyPress installed on the main site on mysite.com

Practically I want users to be automatically redirected to the main site login page every time they try to login from any of the blogs/sites/subdomains.

*.mysite.com/login.php => mysite.com/login.php

Let me give some exemples:

site1.mysite.com/wp-login.php redirected to mysite.com/wp-login.php

site2.mysite.com/wp-login.php redirected to mysite.com/wp-login.php

xyzkw.mysite.com/wp-login.php redirected to mysite.com/wp-login.php


any future subdomain LOGIN PAGE - with no exceptions - will have to be redirected to mysite.com/wp-login.php


You could you do this with redirects through the root .htaccess file;

Something like this perhaps:

# Redirect to new login

<IfModule mod_rewrite.c>

# For security reasons, Option followsymlinks cannot be overridden.

# Options +FollowSymLinks

Options +SymLinksIfOwnerMatch

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain.mysite.com/login.php [OR]

RewriteCond %{HTTP_HOST} ^www.subdomain.mysite.com/login.php [NC]

RewriteRule ^(.*)$ http://www.my-main-site.com/login.php/$1 [L,R=301]


# Redirect end

Or to redirect all sub-domains to the parent, you could try this as a "catch all":

RewriteCond %{HTTP_HOST} !^my-main-site\.com$ [NC]
RewriteRule ^(.*)$ http://my-main-site.com/$1 [L,R=301]

Or if you want to exclude some sub-domains you could do this:

RewriteCond %{HTTP_HOST} !^my-main-site\.com$ [NC]
RewriteCond %{HTTP_HOST} !^excluded-sub\.my-main-site\.com$ [NC]
RewriteRule ^(.*)$ http://my-main-site.com/$1 [L,R=301]

You'll have to have a play to get the login.php working. This link may help: http://www.scriptygoddess.com/archives/2007/06/13/redirect-a-subdomain-to-a-directory-using-htaccess/

  • Is this gonna redirect all my subdomains? I ask because this line looks strange: "RewriteCond %{HTTP_HOST} ^subdomain.mysite.com/login.php [OR]"! Maybe I din't make myself clear, I want all, like *.mysite.com redirect to... – Nicusor Dumbrava Mar 8 '12 at 0:56
  • I edited my answer above to add the catch all, hope that does it for you – SolaceBeforeDawn Mar 8 '12 at 4:49
  • Thank you I will test it, and get back to you, thanks :) – Nicusor Dumbrava Mar 8 '12 at 16:18
  • 1
    I don't want all my subdomains to redirect to the mainsite, I just want all the login pages to redirect to my mainsite login page... [ *.mysite.com/login.php => mysite.com/login.php ] If you know WP has a mysite/wp-admin for every blog/site in a network/multisite installation... and I don't want to customize every login page for every blog, just the one in the mainsite :) ... your code doesn't work for me, I need to customize it when I'll understand .htaccess scripting. – Nicusor Dumbrava Mar 17 '12 at 17:23

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.