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 2 years ago.

Download all attachments as: .zip

Change History (26)

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.

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 2 years ago by bungeshea (previous) (diff)

comment:9 @Frumph2 years ago

Right, but my 'fix' isn't a fix, it's a bypass. The "fix" needs to address the concerns of everyone using it. There *are* people who use NOBLOGREDIRECT on a subdomain installation as intended.

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

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 @jeremyfelt2 years ago

#13689 was marked as a duplicate.

@jeremyfelt2 years ago

comment:15 @jeremyfelt2 years 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 @jadpm2 years ago

  • Cc jadpm added

comment:17 @jeremyfelt20 months ago

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

comment:18 @GrayHunter12 months ago

  • Keywords needs-patch added; has-patch removed

So, when it is going to be fixed??

comment:19 @bungeshea11 months ago

@GrayHunter What more needs to be done?

comment:20 @l3rady10 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 @Jornes836 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 @bungeshea6 months ago

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

comment:23 @slackbot2 months ago

This ticket was mentioned in Slack in #core-multisite by alm. View the logs.

comment:24 @johnjamesjacoby2 months ago

Consider also the name of this constant being indicative of it's intention.

NOBLOGREDIRECT

Which translates to me as:

Redirect to $here when WordPress performed a blog lookup, and found no blog

In @jeremyfelt's testing above, he's correct that the 4th test in the subdomain group is, at the very least, unintended behavior, and should be addressed.

I wonder, though, what happens (and what should happen) in a few other cases:

  • A subdirectory installation, but http://noblog.bar.com is visited
  • A subdirectory installation, but http://noblog.bar.com/hello-world/ is visited
  • A subdirectory installation where the main site is also a subdomain like http://central.wordcamp.org but http://central.wordcamp.org/noblog/ is visited
  • A subdomain installation where the main site is also a subdomain like http://central.wordcamp.org but http://noblog.wordacmp.org/hello-world/ is visited
  • A subdomain installation where the main site is in a subdirectory like http://foo.com/blog/ but http://support.foo.com is visited

There's a bunch of goofy permutations that start to come down to server configuration, and WordPress can (should?) only make so many assumptions about this, and intelligently redirect to the most natural location when it doesn't find anything.

Note: See TracTickets for help on using tickets.