redirect subdomain typo's to correct subdomain


We have a multisite with wildcard subdomains and would like to redirect typo’s.

For example:

correct subdomain is:

wrong subdomain is:

We would like to redirect ->

Any idea’s how to do so?



  • Philip John
    • DEV MAN’s Apprentice

    Hiya Erik!

    This should be fairly simple to do. You could create a custom plugin that will detect the site address and redirect based on that.

    For example;

    function redirect_my_subsite(){
    if ($_SERVER['HTTP_HOST'] == ""){
    wp_redirect( '', 301 );
    add_action('init', 'redirect_my_subsite');

    If you have a lot of mis-spellings you may want to use switch/case instead of IF statements.

    Hope that helps!


  • berlok
    • WPMU DEV Initiate

    Hi Phil.

    Thanks, but i’m not a programmer….

    I copied your code and named the file: redirect_my_subsite.php

    Then uploaded it into wp-content/plugins

    but then i don;t see the plugin?? I also tried to create subdirectory within plugin and named it: redirect_my_subsite. Then i copied the php in it, but also then i don;t see the plugin.

    What i’m doing wrong?



  • Ovidiu
    • Code Wrangler

    I think berlok meant to automatically redirect ANY and ALL typos, right?

    Phil gave an example of how to set up manual redirects, so you’d have to set up one for each possible typo.

    Usually if you want automation, you’d go and implement a nice search on your 404 error page so whenever someone mistypes something, he’d be presented with a search (actually a results page) for his typo giving him some ideas on what went wrong.

    On the other side, in this example, its a multisite install so typing in a non-existing sub-domain will usually send you to the signup page, right? Not sure if one can circumvent this redirection with a 404 error page and if that is the clever thing to do….

    my 2 cents – just some random thoughts that crossed my mind :slight_smile:

  • berlok
    • WPMU DEV Initiate

    Yes on your last question, but the problem is that we need visitors who visit see exact the same page as the visitors who come thru (here they can select a blog).

    BUT we already use the noblogredirect code for type errors and non existing blogs. These visitors are redirected to page with the possibility to start their own blog.

    So the problem is how to show both the as the visitors the same page with the noblogredirect code already in use.

  • Ovidiu
    • Code Wrangler

    I’m sorry I cannot replicate this.

    on my install and both show the same content and users with www are redirected to – this is the default behavior so far with sub directory installs and shoulwdbe handled by the .htaccess file.

    is this the same behavior you have so far?

    not for testing, I added the noblogredirect option and entering sent me to my redirect page. still works.

    if this is not the case with you, please do post your .htaccess file here.

  • berlok
    • WPMU DEV Initiate

    Sorry for late reaction, just tried a couple of different .htaccess files, but all result in same problem.

    The redirect noblogredirect is working perfect, the problem is www. and no front of url redirect.

    Other domain with no multisite wordpress installation doesn’t have this problem

  • Ovidiu
    • Code Wrangler

    sorry but I still don’t understand your situation.

    lets try again and forget about the noblogredirect.

    does http://www.yourdomain.tld redirect you to yourdomain.tld ?

    if it does, that is the default behavior of multisite.

    now adding define('NOBLOGREDIRECT', 'http://mydomain.tld/' ); should send xxgsg.yourdomain.tld and xxgsg.www.yourdomain.tld to yourdomain.tld, does it or does it not?

  • berlok
    • WPMU DEV Initiate

    Ok let me try it like this:

    We use the noblogredirect for non existing url’s like These visitors are redirected to error page:

    If visitors enters in browser then he/she sees index page (correct).

    If visitors enters in browser then he/she sees sign-up page (default page when a site does not exist in WP), but because of noblogredirect he/she sees the page.

    How to make the and the the same. Again we already use the noblogredirect.

  • Ovidiu
    • Code Wrangler

    How to make the and the the same. Again we already use the noblogredirect.

    it seems you have done some mods to your .htaccess file since wp multisite does by default redirect the www-version of a site to the non-www version.

    could you post your .htaccess file here? I’n not very good at checking those but others might be able to spot something…

  • berlok
    • WPMU DEV Initiate

    Indeed i’ve added some things, but when i upload the standard wordpress multisite htaccess file it is still not working:

    RewriteEngine On

    RewriteBase /

    RewriteRule ^index.php$ – [L]

    # uploaded files

    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [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).*) $1 [L]

    RewriteRule ^[_0-9a-zA-Z-]+/(.*.php)$ $1 [L]

    RewriteRule . index.php [L]

  • Ovidiu
    • Code Wrangler

    hm, as I’ve said I’m not good with .htaccess files but maybe someone can spot something from your file.

    meanwhile could someone please test this scenario since it seems to work for me:

    make sure http://www.yourdomain.tld gets redirected to yourdomain.tld as is the multisite default?

    then please add a noblogredirect like this: define('NOBLOGREDIRECT', 'http://mydomain.tld/some-existing-page/' ); and check again what happens if you access http://www.yourdomain.tld versus yourdmain.tld please?

  • Ovidiu
    • Code Wrangler

    well, I do hope someone else chimes in here since I can only speak from my experience: wordpress generally (no multisite) redirects to the version of your site that you have selected under

    WordPress address (URL) or Site address (URL) can’t exactly remember which one affected it but on any stock wordpress install, one points to another, which one (www or non-www) you chose is up to you while on multisite-enabled sites, you always get the www stripped unless you hack your .htaccess or other nasty stuff.

    Just my 2cents and as to why it doesn’t happen on your install, I have no idea, honestly. I do hope someone else speaks up too, don’t wanna leave you hanging like this.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.