Make WordPress Core

Opened 3 years ago

Last modified 4 months ago

#21573 new defect (bug)

NOBLOGREDIRECT interfering with 404 errors

Reported by: bungeshea Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4.1
Component: Bootstrap/Load Keywords: needs-patch
Focuses: multisite Cc:


When the NOBLOGREDIRECT constant is defined, 404 pages on the main site will not work and instead redirect to URL defined in NOBLOGREDIRECT. This is the cause of the maybe_redirect_404 action/function, which is not needed and should be removed.

Attachments (2)

21573.patch (748 bytes) - added by bungeshea 23 months ago.
Bail early in maybe_redirect_404 function on subdomain installs
21573.2.diff (713 bytes) - added by jeremyfelt 18 months ago.

Download all attachments as: .zip

Change History (22)

comment:3 @bungeshea3 years ago

It seems that the main purpose of this function was intended for sub-directory installs; it should be modified to first check if a subdomain install is active and, if so, bail early.

comment:5 @bungeshea23 months ago

@ottok I have applied the fix to my own site (@Fruumph actually posted that same link above), but I thought a fix should be implemented into core.

@bungeshea23 months ago

Bail early in maybe_redirect_404 function on subdomain installs

comment:6 @bungeshea23 months ago

  • Keywords has-patch added; needs-patch removed

comment:7 @Frumph23 months ago

@bungeshea what about those people who would want to use the define on subdomain installs?

validsubdomain.domain.com/notvalidsuffix/ this needs to redirect to error page

notvalidsubdomain.domain.com/ this needs to be able to use the define

comment:8 @bungeshea23 months ago

@Frumph I'm actually testing this code on my own site, and the behaviour is the same as when using the fix you posted about.

http://notvalidsubdomain.bungeshea.com/ redirects to location defined in NOBLOGREDIRECT (in this case, main site)

http://code-snippets.bungeshea.com/notvalidsuffix/ uses usual 404 error page

Last edited 23 months ago by bungeshea (previous) (diff)

comment:9 @Frumph23 months ago

Your NOBLOGREDIRECT goes to the root page of the site is what you have it set for?

(re-read your comment)

Last edited 23 months ago by Frumph (previous) (diff)

comment:10 @bungeshea23 months ago

So what would you suggest? An option in Network Settings, perhaps?

comment:11 @Frumph23 months ago

No, my apologies, if the behavior you state is happening then i'm very cool with the end result.

the 404's going to the appropriate 404 page and the wrong subdomain going to the noblogredirect, that's expected behavior and how it should be. If your fix does that, then cool.

comment:12 @bungeshea23 months ago

Yep, that's what it does alright. It just disables the 404-redirect-to-NOBLOGREGIRECT-functionality on the front-end only, and only for subdomain installs (subdirectory installs aren't affected). The wrong-blog-redirect functionality is handled elsewhere.

Last edited 23 months ago by bungeshea (previous) (diff)

comment:13 @Frumph23 months ago

Cool yeah, expected behavior ftw.

comment:14 @jeremyfelt18 months ago

#13689 was marked as a duplicate.

@jeremyfelt18 months ago

comment:15 @jeremyfelt18 months ago

  • Milestone changed from Awaiting Review to Future Release

In a nutshell, from this ticket and #13689, with NOBLOGREDIRECT defined...

If I have /test/ setup as a subfolder site at mydomain.com:

  1. http://mydomain.com/test/ works
  2. http://mydomain.com/test/notapageurl/, or any non existent URL on the subfolder site, gives me a /test/ 404
  3. http://mydomain.com/anythingotherthantest/, or any non existent URL on the main site, redirects to the URL specified in NOBLOGREDIRECT

If I have test.mydomain.com setup as a subdomain site:

  1. http://test.mydomain.com works
  2. http://test.mydomain.com/notapage, or any non existent URL on the subdomain site, gives me a test.mydomain.com 404
  3. http://notsubdomain.mydomain.com redirects to the URL specified in NOBLOGREDIRECT
  4. http://mydomain.com/notapage, redirects to the URL specified in NOBLOGREDIRECT

It's that last item, where a 404 belonging to the primary site redirects to NOBLOGREDIRECT in a subdomain install, that is at the heart of the issue here. I would agree that this seems like unexpected behavior, though it appears like it has always been the behavior.

The current logic in maybe_redirect_404() checks for is_main_site(), but as stated earlier in this ticket and in the other, should probably look at is_subdomain_install() as subdomains are much easier to determine intent with when trying to guess if dealing with a missing site or a missing page.

21573.2.diff is a slight variance from the patch uploaded by bungeshea and adds ! is_subdomain_install() to the check before redirecting.

comment:16 @jadpm17 months ago

  • Cc jadpm added

comment:17 @jeremyfelt13 months ago

  • Component changed from Multisite to Bootstrap/Load
  • Focuses multisite added

comment:18 @GrayHunter6 months ago

  • Keywords needs-patch added; has-patch removed

So, when it is going to be fixed??

comment:19 @bungeshea5 months ago

@GrayHunter What more needs to be done?

comment:20 @l3rady4 months ago

This bug has just caught me out. Would love to see this patched in the next WP version.

Note: See TracTickets for help on using tickets.