Make WordPress Core

Opened 12 years ago

Last modified 3 months ago

#21573 new defect (bug)

NOBLOGREDIRECT interfering with 404 errors

Reported by: bungeshea's profile bungeshea Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4.1
Component: Bootstrap/Load Keywords: needs-patch needs-unit-tests
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 12 years ago.
Bail early in maybe_redirect_404 function on subdomain installs
21573.2.diff (713 bytes) - added by jeremyfelt 11 years ago.

Download all attachments as: .zip

Change History (28)

#3 @bungeshea
12 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.

#5 @bungeshea
12 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.

@bungeshea
12 years ago

Bail early in maybe_redirect_404 function on subdomain installs

#6 @bungeshea
12 years ago

  • Keywords has-patch added; needs-patch removed

#7 @Frumph
12 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

#8 @bungeshea
12 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 12 years ago by bungeshea (previous) (diff)

#9 @Frumph
12 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 12 years ago by Frumph (previous) (diff)

#10 @bungeshea
12 years ago

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

#11 @Frumph
12 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.

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

#13 @Frumph
12 years ago

Cool yeah, expected behavior ftw.

#14 @jeremyfelt
11 years ago

#13689 was marked as a duplicate.

@jeremyfelt
11 years ago

#15 @jeremyfelt
11 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.

#16 @jadpm
11 years ago

  • Cc jadpm added

#17 @jeremyfelt
11 years ago

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

#18 @GrayHunter
10 years ago

  • Keywords needs-patch added; has-patch removed

So, when it is going to be fixed??

#19 @bungeshea
10 years ago

@GrayHunter What more needs to be done?

#20 @l3rady
10 years ago

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

#21 in reply to: ↑ description @Jornes83
10 years 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?

#22 @bungeshea
10 years ago

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

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


9 years ago

#24 @johnjamesjacoby
9 years 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.

This ticket was mentioned in Slack in #core by mbootsman. View the logs.


8 years ago

#26 @jorbin
3 months ago

  • Keywords needs-unit-tests added

It would be good to see if @jeremyfelt's research is till valid and also get this functionality tested in an automated way.

Note: See TracTickets for help on using tickets.