How to properly print a 404 error without redirecton? (i.e. keeping the current URL)

You should be using a filter outside of your template for this: add_filter( ‘template_include’, ‘wpa62226_template_include’, 1, 1 ); function wpa62226_template_include( $template ){ if( is_page( ‘some-page’ ) ) : global $wp_query; $wp_query->set_404(); status_header( 404 ); $template = locate_template( ‘404.php’ ); endif; return $template; } Your code is executed before the template is loaded, so it becomes … Read more

What form element names break wordpress?

You should definitely avoid the public WordPress query vars: attachment attachment_id author author_name cat category_name comments_popup day error feed hour hour m minute monthnum name p page_id paged pagename post_parent post_type preview second static subpost subpost_id tag tag_id tb w year There’s also this list of reserved terms, inexplicably located on the register_taxonomy page, with … Read more

Resolve 404 on posts without category

Ok, resolved it in 404.php <?php $klo_link = $_SERVER[‘REQUEST_URI’]; if (preg_match(“/^\/[a-zA-Z0-9\-\_]+\/$/”, $klo_link)) { //echo “A match was found. \n”; //echo $klo_link; header(“HTTP/1.1 301 Moved Permanently”); header(“Location: “.get_bloginfo(‘url’).”/a”.$klo_link); exit(); }else { get_header(); } Put that at the beginning of the 404.ph

WordPress refuses to read the .htaccess file and gives a 404 for sub-pages

Even though the 000-default.conf file had… <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> I had to place… <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Require all granted </Directory> Into the apache2.conf And use the sudo service apache2 restart command.

Page not found (404 Error) even if the page exists?

Change your current permalink structure to the WordPress Default Permalink structure and then again change it back to your current permalink structure. Hope it will work! If not then clear your browser cache and use Wp Super Cache plugin to clear WordPress Cache. and then open the URL test.mydomain.com/wordpress/hello/