How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?

.htaccess skip WordPress 404 error handling for static files. <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(robots\.txt|sitemap\.xml(\.gz)?) RewriteCond %{REQUEST_FILENAME} \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC] RewriteRule .* – [L] </IfModule> Note: These rules were generated by the W3 Total Cache plugin* Nginx skip WordPress 404 handling for static files. if (-f $request_filename) { break; … Read more

How to redirect non-logged in users to a specific page?

Here are 2 examples which you will need to modify slightly to get it working for your specific needs. add_action( ‘admin_init’, ‘redirect_non_logged_users_to_specific_page’ ); function redirect_non_logged_users_to_specific_page() { if ( !is_user_logged_in() && is_page(‘add page slug or ID here’) && $_SERVER[‘PHP_SELF’] != ‘/wp-admin/admin-ajax.php’ ) { wp_redirect( ‘http://www.example.dev/page/’ ); exit; } } Put this in your child theme functions … Read more

Redirect Restricted Page to 404

I was able to display a 404 error by using the following code in my header. <?php global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); ?> To break it down: $wp_query->set_404(): tells the wp_query this is a 404, this changes the title status_header(): sends a HTTP 404 header get_template_part(): displays the 404 template

How to force a 404 on WordPress

You could try the WordPress function status_header() to add the HTTP/1.1 404 Not Found header; So your Code 2 example would be: function rr_404_my_event() { global $post; if ( is_singular( ‘event’ ) && !rr_event_should_be_available( $post->ID ) ) { global $wp_query; $wp_query->set_404(); status_header(404); } } add_action( ‘wp’, ‘rr_404_my_event’ ); This function is for example used in … Read more

PHP header(Location: …): Force URL change in address bar

I’m currently working on a mobile site with authentication using PHP sessions with a database. I have a login page with a form that goes to server_login.php on submit. The php file then creates some session data (store in $_SESSION), and redirects the user back to the index page: The new web page (index.php) loads correctly; however, … Read more