My primary website on a multisite network was created with the www prefix (like www.example.com).

If I try to access pages without the www prefix (like example.com/page-name/ instead of www.example.com/page-name/, I am redirected to the homepage (www.example.com). I would like to change this so I am redirected simply redirected to the same page URL, only with the www prefix.

Additionally, the 404 error page doesn't work on the primary site. No matter which non-existant URL I try (such as www.example.com/thisdoesnotexist), I am always redirected to the primary site home page (www.example.com), rather then seeing the theme's 404 page.

Here is a link to my site where you can test the issue.

  • example.com/thisisalsoawrongurl and www.example.com/thisisawrongurl, despite www, should trigger a 404 error; if not that is also a problem. Please, provide more information about URL configuration, possible .htaccess rules and any other you may consider important for this issue, otherwise it is very difficult to answer, if not impossible.
    – cybmeta
    Commented Mar 17, 2015 at 7:02
  • Cybmeta, i did updated the post. Kindly have a look at it. That is the original code after i created the multisite.
    – Jornes
    Commented Mar 17, 2015 at 9:51
  • 1
    The .htaccess you posted is for multisite using subdirectories. See the codex to find the .htaccess you should use for multisites using subdomains.
    – cybmeta
    Commented Mar 17, 2015 at 16:36
  • Hi Cybmeta, i have updated the post. And this is the htaccess code i copied from that page you linked above. Is this what you trying to say? But, the redirect does not work no matter which code i tried.
    – Jornes
    Commented Mar 17, 2015 at 17:21
  • If you've tried everything else, please make sure that your hosting service / web server supports htaccess files. If your httpd.conf does not have AllowOverride All set for your site's root directory, the htaccess file will be ignored. Commented Mar 17, 2015 at 19:39

2 Answers 2


There is currently a bug in the functionality that handles the NOBLOGREDIRECT constant, which causes 404 errors on the main site to be redirected to the value of the constant. Apparently this is the expected behaviour for sub-directory networks (example.com/subsite), but should not take place on subdomain networks (subsite.example.com).

There is a WordPress Trac ticket (#21573) concerning this bug, but there is no indication on when it might be resolved. Until then, you can resolve this error yourself by removing the maybe_redirect_404 function:

remove_action( 'template_redirect', 'maybe_redirect_404' );

This code should go in a .php file in the wp-content/mu-plugins directory. Remember to include a <?php tag at the beginning of the file.

  • Hi Shea, I don't have this folder named mu-plugins in current directory of wp-content/. Shall it be created by my own? If so, what name should i name for the .php file?
    – Jornes
    Commented Mar 20, 2015 at 6:20
  • 1
    Yes, just create the mu-plugins folder inside the wp-content directory. The PHP file can be pretty much any name you want, though lowercase without spaces is a good way to go. For example, custom.php. Remember to include <?php at the beginning of the file.
    – shea
    Commented Mar 20, 2015 at 9:45
  • Hi @shea, thank you so much! I have done this step. But, i am still need some further solution. Now, i have the same issue which i mentioned earlier in the comment. Which is, when i type any page's url without www, the site would redirect to home page instead. All the existing urls is only work when it's with www. Otherwise, it would redirect to homepage.
    – Jornes
    Commented Mar 20, 2015 at 10:42
  • It's not recommended to use www as part of your main site URL in subdomain networks precisely this reason. At this point, it's probably best to use a redirection on the .htaccess level
    – shea
    Commented Mar 20, 2015 at 11:26
  • Hi Shea, noted. How do I make changes to the setting that makes my main site from www to non www without using htaccess. I tried to remove the www from the url in the database but the result turns out to say I have a redirect loop.
    – Jornes
    Commented Mar 21, 2015 at 4:18

check your .htaccess for

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

this is the basic htaccesss parameters a wordpress installation creates during installation. Line no. 3 is important.

  1. Check your database options table for proper siteurl and home value for http://www.yourdomainname.com.
  • Hi Shreyo Gi, the content of my .htaccess is exactly same. And, i did checked the database as well. The settings are correct. Just wondering why and looking for solution against this issue.
    – Jornes
    Commented Mar 17, 2015 at 9:12
  • well, can you go to permalinks under settings and select your preferred URL structure and save it again? It happened for me once and re-saving the URL did the job.
    – Shreyo Gi
    Commented Mar 17, 2015 at 9:30
  • Shreyo Gi, nothing to do with permalink. By the way, i did this setting i'm creating this site.
    – Jornes
    Commented Mar 17, 2015 at 9:32
  • 1
    Jornes, please, don't say that your .htaccess is exactly the same when it is obviously not; you posted a quite different .htaccess file in your question. And Shreyo, the .htaccess you posted is not suitable for Multiste installations, which the case of this question.
    – cybmeta
    Commented Mar 17, 2015 at 10:31
  • Sorry! I did not declare clear enough previously. Yes! The .htaccess was exactly same as what Shreyo said in his answer. But, i got a new code from somewhere else while i was searching for the solution. So, i added it on. The code i copied and pasted on updated part is the new code. But, it doesn't work as well.
    – Jornes
    Commented Mar 17, 2015 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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