Changeset 3476554
- Timestamp:
- 03/06/2026 04:11:44 PM (4 weeks ago)
- File:
-
- 1 edited
-
404-to-homepage/trunk/404-to-homepage.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
404-to-homepage/trunk/404-to-homepage.php
r3466005 r3476554 12 12 add_action('template_redirect', function() { 13 13 14 if ( 15 wp_doing_ajax() || 16 wp_doing_cron() || 17 is_admin() || 18 (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) || 19 (defined('REST_REQUEST') && REST_REQUEST) 20 ) return; 14 if (wp_doing_ajax() || wp_doing_cron() || is_admin() || (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) || (defined('REST_REQUEST') && REST_REQUEST)) return; 21 15 22 16 if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') return; … … 26 20 $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); 27 21 28 // Skip direct PHP file access29 22 if (substr($path, -4) === '.php') return; 23 24 if (substr($path, -4) === '.txt') return; 30 25 31 // Skip sitemap32 26 if (strpos($path, 'sitemap.xml') !== false) return; 33 27 … … 43 37 global $wp_query; 44 38 45 // Reliable low-level 404 check46 39 if (empty($wp_query) || empty($wp_query->is_404)) return; 47 40 … … 54 47 55 48 }, PHP_INT_MAX); 56 57 /*58 add_action('template_redirect', function() {59 60 if (wp_doing_ajax() || wp_doing_cron() || is_admin() || (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)) return;61 62 if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'sitemap.xml') !== false) return;63 64 global $wp_query;65 if ($wp_query->is_404 === false) return;66 67 if (wp_safe_redirect(home_url('/'), 301)) die;68 69 }, PHP_INT_MAX);70 */
Note: See TracChangeset
for help on using the changeset viewer.