It is, in most cases, a logical thing to show the homepage even when there are querystrings available. Never the less, I’m assuming you have a reason for this. You could try code below to redirect your visitors to your 404 page:
if ( isset($_GET) ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
}
Keep in mind that some other functionality might break because of this. You may want to add some additional conditionals.
Related Posts:
- Extra Text in URL
- How do I redirect the browser to 404 page, if no posts are found in home page
- How to force a 404 on WordPress
- Redirect Restricted Page to 404
- How to prevent automatic redirection of 404 errors and “incorrect” URLs?
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- When I change slug, will WordPress create redirect from the old URL?
- How do I programmatically generate a 404?
- Stop WordPress Redirection From /keyword to /some-post-containing-keyword/
- How do I skip wordpress’s 404 handling?
- Redirecting to home-page when saving any edited code
- Random and Erroneous WordPress Redirect
- 404 redirection and Google’s index [closed]
- Redirect feed to 404 page
- What is the wordpress way of displaying local external content?
- Check if post is in draft or pending review?
- Does WordPress automatically redirect url without parent slug?
- Import WordPress Post Slug with Forward Slash
- All pages showing up as homepage on WordPress website
- Why specific file directory fails to redirect but its parent folder succeeds?
- https multiple redirects
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- Deny access to a path (give 403 or 404 response)
- Redirect home to another page with htaccess
- Redirect a page id url but not the page slug
- How can I redirect my website’s homepage to a random blog post?
- How to redirect to home page after registration?
- How to set up a single portfolio page as home page?
- Defining a custom 404 for non-WordPress parts of site
- Any action in wordpress redirects me to home page
- How can I replace my primary url globally with a parked one?
- WordPress Auto-Redirecting on 404
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- Problem in disabling canonical 301 redirect
- Keep subcategory grandson in slug
- How to redirect a wrong search on my wordpress website to the error 404 page?
- WP page 404 error only on mobile
- Issue redirecting ‘blog’ to ‘news’ in WordPress using .htaccess
- Force 404 redirect to home?
- Redirect /home to home.php
- How to delete a post and keep its slug to refer to another post
- How can I redirect users on the new 404 page without plugin?
- How to redirect an old page url to the homepage
- Dynamic 404 page content while still keeping 404 status code?
- Delete Redirect Slug For Specific Post
- Redirect to home if page doesn’t exists [duplicate]
- Redirect to parent page if child does not exist
- How do I change the home page to the registered user’s profile page
- Unwanted slug in my website
- How to redirect non existent pages/posts in wordpress using htaccess
- How to redirect all page requests to a single “goodbye” homepage? [duplicate]
- Add new post redirection [closed]
- pagination 404 error, same slug home and categories
- Add base folder to CPT and 301
- How do i make WordPress return 404 instead of redirecting on misspelled page?
- How to redirect if 404 error in wordpress then redirect 404.php url
- Site using static homepage, redirects (301) and removes pluses from query string
- Redirect to /404/
- multisite 404 subfolder same name slug as site
- Page editing in backend redirecting to 404 page not found with url /post.php
- After disabling Multisite, homepage redirects to non-existing page
- change home_url and site_url but don’t redirect to home_url and site_url on load
- How do I skip wordpress’s 404 handling?
- My question:When I started my website, the “page not found” error always came up
- After Migration From dev, Only my Links to the Homepage Still Redirect to dev
- One set of Child Pages redirecting to Home page?
- Redirect to Page after Login (with variable)
- .htaccess not working after page slug change
- International characters in slugs to redirect to
- Blog post URL redirects to a Page URL who’s slug is a prefix of the post slug.
- Subpages return 404 server error
- Show page without reference to post (like front-page)
- WordPress subfolders htaccess bypassing the root htaccess RewriteRule
- Why my htacess rewrite return 404?
- How to Redirect Url to homepage?
- WordPress Redirecting Form Action to Home Page
- How do make WordPress to let alone my static home page?
- Stopping media file redirects
- Forcing header cache control in 404 pages
- Home page returns 404
- redirect to 404 page
- Redirect certain 404 pages to parent page
- Make category page the wordpress homepage (not blog)
- Change Website Homepage from WordPress to Xenforo
- Redirect of specific words in URL ahead of website migration
- Non-existent URLs/slugs redirect to default Posts page
- PHP header(Location: …): Force URL change in address bar
- What does HTTP/1.1 302 mean exactly?
- php refresh current page?
- Disable front end to use as CMS only?
- How to redirect non-logged in users to a specific page?
- Disable WordPress URL auto complete
- Host the wp-admin on another domain?
- Redirect user to original url after login?
- WordPress localhost site redirect to live site
- WordPress redirecting connections on port 8080 to 80
- WordPress Redirect All HTTP requests to HTTPS via .htaccess
- wp_redirect() function is not working
- Redirect entire website to a single page
- My wordpress multisite homepage redirects to signup page