When clean urls are enabled, non-existant pages are rewritten to www.site.com/?q=non/existant. The menu handler will throw a 404 on the non-existant Drupal path.

However, if clean urls are not active, then the 404 page (index.php) is called as is. $GET['q'] will be empty, and the front page will be shown without any indication of the 404 or without a log entry in the watchdog. Note that this only happens if .htaccess is being read, but mod_rewrite is not present or enabled. Not too common, but still a bug.

The attached patch fixes this problem by checking for a 404 in index.php and calling drupal_not_found() if needed. It also sets $_GET['q'] to request_uri(), so the 404'd URL shows up correctly in the watchdog (same as the rewrite rule).

This should go in 4.5 as well as HEAD. Patch is for HEAD, but it should apply to 4.5.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven’s picture

An alternative solution is to drop the ErrorDocument 404 from .htaccess, then the web server will handle them if there are no clean URLs. However I think the intended behaviour is for Drupal to log all 404s.

killes@www.drop.org’s picture

Doesn't apply anymore.

killes@www.drop.org’s picture

Status: Active » Needs work

Steven what's up with this?

Steven’s picture

As far as I can tell, the issue is still there. I can't make an updated patch atm. Either we need to check for a non-clean 404, or stop intercepting non-clean 404s.

It affects setups where htaccess is being read, but mod_rewrite is not installed or not working.

neclimdul’s picture

I can't reproduce this on HEAD(5.0) or 4.7.

neclimdul’s picture

Status: Needs work » Fixed

After testing with a disabled mod_rewrite I'm fairly certain this has been fixed already.

Anonymous’s picture

Status: Fixed » Closed (fixed)
JeremyFrench’s picture

Version: » 7.0-alpha7
Assigned: Steven » Unassigned
Priority: Normal » Major
Status: Closed (fixed) » Needs work

I think I will have to re open this. As it is kind of broken with D7 now.

I did an install of drupal 7 alpha 7 on a server with no mod rewite. It looked like everything was fine, and the install wen't ok. Pages were showing ok.

BUT.

Forms would not submit, and every page was returning a 404 code, but with the correct content for the page. I only realised abuot the 404 code as I had firebug on.

This is kind of an inciduous and evil bug, as I didn't realise that mod rewrite was disabled and clean urls looked like they were working, it was only after hacking around with the rewite rules to find out what was going on that I realised that it was the 404 handler which was causing the issue. But that was the best part of an afternoon spent trying to work out what was up.

I am bumping to major as it can break Drupal.

It would be nice to see if anyone else can recreate.

JeremyFrench’s picture

Looking into this a little.

I think this is more prevalent as request_path() will parse a clean URL, even if clean urls are off. So if index.php gets called by the 404 handler instead of mod_rewite it can look like the site is working.

I can see a couple of ways to stop this, none ideal
1. request_path could honor clean urls, but this would make testing if clean urls work problematic
2. We could make the 404 handler in .htaccess conditional on mod rewrite being enabled, but as mod rewrite handles non existent files would this do anything?.
3. We could check in Drupal (somehow) to see if we are being called from the 404 handler or mod rewrite.
4. We could have the 404 handler go to a file other than index.php so we can flag that this is a file not found.

JeremyFrench’s picture

FileSize
1.21 KB

I have looked into this some more and created a patch. It occurs when a server becomes misconfigured and clean urls no longer work. To reproduce is easy.

On your server turn off mod rewrite, then try to log in and disable clean urls.

You won't be able to, as the 404 handler doesn’t pass on form variables, as well as forcing a 404 return code for each request.

This essentially makes a Drupal site unusable, and it is not obvious what has happened, or even that things are broken until you try to submit a form.

The patch will check to see if what appears to Drupal to be a valid URL is also considered so by the web browser, if not, it will alert the user and turn clean URLs off.

JeremyFrench’s picture

Version: 7.0-alpha7 » 7.0-beta2
JeremyFrench’s picture

Version: 7.0-beta2 » 7.x-dev
JeremyFrench’s picture

FileSize
1.23 KB

Updating patch to get rid of tabs

JeremyFrench’s picture

Status: Needs work » Needs review
neclimdul’s picture

Patch seems to fix as expected. Couple things though.

  1. the drupal_set_message probably isn't necessary.
  2. meens should be means
  3. The behavior still exists if clean_urls are turned off and you hit a clean url. You should probably separate the variable set from the redirect. This might also affect the watchdog.
  4. There should be spaces after commas for all your function arguments. watchdog and drupal_set_message are missing them.
neclimdul’s picture

Status: Needs review » Needs work
JeremyFrench’s picture

Status: Needs work » Needs review
FileSize
1.37 KB

@neclimdul Thanks for the review. Points 2,3 & 4 have been addressed.

I'm not sure about point 1, it may be useful to alert someone to the fact that something has just broken as it isn't immediately apparent unless you are keeping an eye on the URLs.

neclimdul’s picture

Well, that may be but your average site visitor doesn't care or understand what that means. That's what the watchdog does. I don't know if we have this sort of failure logic documented anywhere but it is consistent with handling other sorts of failures in core.

derjochenmeyer’s picture

#17: drupal-13594-3.patch queued for re-testing.

derjochenmeyer’s picture

The patch in #17 works as expected.

Another way to reproduce this behaviour and test the patch is by setting up a fresh D7 install with clean urls enabled. Then turn the RewriteEngine off in your .htaccess

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine off

The site returns "307 Temporary Redirect", clean urls are deactivated.

amc’s picture

neclimdul’s picture

I'm not sure since this isn't directly associated with the Overlay module. That said, the problem with Overlay may be symptom and that would make it a duplicate.

Why don't you try the patch and see if it fixes the problem? I don't think there was anything keeping this from being RTBC other than I wasn't comfortable forcing that message to sit visitors.

Can you image if you saw something like that on Facebook? Some user would be like "Short URLs? WTF and why do I care?" Then there would be a post on thedailywtf and we'd all laugh at them.

derjochenmeyer’s picture

FileSize
1.08 KB

I removed the set_message and some whitespaces from JeremyFrench's patch #17.

Starbuck’s picture

I have a brand-new install of D7 and I ran into this issue. I checked this site for issues related to a 404 message. I found #886182: Editing Path in Page Redirects to admin/content 404 and that led me here.

I applied the patch from #23 and the issue has indeed been fixed. I'm hoping this makes its way back into core.

For this issue there is a common question "Are clean URLs enabled?" Personally, I have no idea. When I go to Administration » Configuration » Search and metadata » Clean URLs, and run the test, the page refreshes, but there is no success/fail message. Looking at the site with a non-registered user I don't see clean URLs, so I'm assuming it's turned off. So where do we turn it on and how can we really verify that it's on or off?

Thanks!

[EDIT] It looks like the problem persists if the admin overlay is not in use, but when overlay is in use, the 404 does not occur. I'm not 100% sure of the cause/effect situation here but will post if I can narrow it down.

sun’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » task
Issue tags: +Needs backport to D7

Patch looks good. Wondering whether we could test this in any way (hacks).

JeremyFrench’s picture

I couldn't think of a way to automate the testing.

If you want to test manually it is fairly straightforward (from memory). Install a site on a server with mod rewrite working. Then disable mod rewrite in your Apache config (and restart).

Without the patch the site will look like it is working, but you will be unable to login (or do any post form submission).

With the patch clean urls should be turned off and login should then work.

pillarsdotnet’s picture

So the test would be to change the same things that the "clean urls" test changes (thus simulating that it once passed), and then try to log in. If the login succeeds, the test passes.

quicksketch’s picture

Priority: Major » Normal
Status: Needs review » Needs work

Reading over this patch, I can immediately see a DrupalWTF coming out of it. If I made an accidental change to .htaccess or Apache that busted clean URLs, I'd probably notice quickly. In this hypothetical situation, I'd appreciate Drupal changing to non-clean URLs temporarily, but if I then corrected the issue with .htaccess/Apache my expectation would be that clean URLs would start working again immediately. This situation could go terribly wrong when dealing with multi-site situations where you'd have to go through dozens of sites and manually re-enable clean URLs on every one of them.

Additionally, most users have no idea what Clean URLs are at all. They don't know what they're called or why they wouldn't come back on immediately after correcting the problem with their server. I'd suggest that we make this change temporary (memory-only) by setting $GLOBALS['conf']['clean_urls'] = 0; before the call to drupal_goto() rather than saving the change to the database. "Automatically" changing configuration and leaving the user with no idea how to turn it back on is a hundred support requests just waiting to happen.

Additionally the watchdog message is incredibly vague (couldn't we at least add a link to the Clean URLs configuration page?) and should describe how to remedy the problem rather than making a vague statement. I'd suggest something like this:

The Clean URLs option was enabled but the server does not seem to support rewriting URLs. Check your server configuration to ensure rewriting URLs is supported or permanently disable Clean URLs under the <a href="!url">Clean URLs setting page</a>.
neclimdul’s picture

@quicksketch thanks for digging this up and reviewing!

That is a very nice watchdog message! I'm for changing it.

I'm not sure about the not setting the variable though. If we don't there will be a swarm of watchdog messages until the site administrator figures out there's a problem.

JeremyFrench’s picture

I'm thinking that we would need a separate variable. To say that clean urls had been fixed, with a periodic check to enable again if they are working.

I'm also not sure if form submissions would be passed to pages if they are 302 redirected (I haven't tested though).

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: drupal-13594-4.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.