Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.416
diff -u -p -r1.416 menu.inc
--- includes/menu.inc	21 Oct 2010 11:56:17 -0000	1.416
+++ includes/menu.inc	29 Oct 2010 09:59:19 -0000
@@ -473,6 +473,17 @@ function menu_execute_active_handler($pa
       menu_rebuild();
     }
     if ($router_item = menu_get_item($path)) {
+      // If we are on a valid page and the server has responded with a 404
+      // and clean urls are on, it meens mod rewrite is broken and clean urls
+      // are not working properly. Flag error and redirect.
+      if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 404 && variable_get('clean_url', '0')) {
+        watchdog('system', 'System no longer supports clean URLs, turning off automatically.',array(),WATCHDOG_WARNING);
+        drupal_set_message(t('System no longer supports clean URLs, turning off automatically.'),'warning');
+	variable_set('clean_url', 0);
+	drupal_goto($read_only_path);
+      }
+
+
       if ($router_item['access']) {
         if ($router_item['include_file']) {
           require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
