WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 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:

Description

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 2 years ago.
Bail early in maybe_redirect_404 function on subdomain installs
21573.2.diff (713 bytes) - added by jeremyfelt 21 months ago.

Download all attachments as: .zip

Change History (24)

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 @bungeshea2 years 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.

@bungeshea2 years ago

Bail early in maybe_redirect_404 function on subdomain installs

comment:6 @bungeshea2 years ago

  • Keywords has-patch added; needs-patch removed

comment:7 @Frumph2 years 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 @bungeshea2 years 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.

Version 0, edited 2 years ago by bungeshea (next)

comment:9 @Frumph2 years ago

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

(re-read your comment)

Last edited 2 years ago by Frumph (previous) (diff)

comment:10 @bungeshea2 years ago

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

comment:11 @Frumph2 years 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 @bungeshea2 years 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 2 years ago by bungeshea (previous) (diff)

comment:13 @Frumph2 years ago

Cool yeah, expected behavior ftw.

comment:14 @jeremyfelt21 months ago

#13689 was marked as a duplicate.

@jeremyfelt21 months ago

comment:15 @jeremyfelt21 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 @jadpm20 months ago

  • Cc jadpm added

comment:17 @jeremyfelt16 months ago

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

comment:18 @GrayHunter9 months ago

  • Keywords needs-patch added; has-patch removed

So, when it is going to be fixed??

comment:19 @bungeshea8 months ago

@GrayHunter What more needs to be done?

comment:20 @l3rady6 months ago

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

comment:21 in reply to: ↑ description @Jornes832 months ago

Replying to bungeshea:

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.

Now, I removed the line of NOBLOGREDIRECT in my wp-config file and the error page on main site is working but the link must be together with www or else it turns out to this url http://www.example.my/wp-signup.php?new=example.com when i type any url without "www". I tried to fix this with .htaccess file to make it work. But, it would affect all the subdomain redirect to www as well. Example result: www.sub1.example.com. I don't want this happen to my sub domain. Any php code i can implement into wp-config to get this resolved?

comment:22 @bungeshea2 months ago

@Jornes83: Please don't post support requests here, instead use WordPress Developers or the Forums.

Note: See TracTickets for help on using tickets.