Recently I Found some error on WordPress sites that when someone enter a question mark after the root domain and type any word, url shows the Home Page of instance:

For instance, Root Domain is abc.com abc.com/?anyword should be reached on the 404 not found page which shows the home page.

I need help with this Issue: https://www.iadm.edu.pk/?anyword should be redirected to the 404 not found page.

1 Answer 1


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;
    status_header( 404 );
    get_template_part( 404 );

Keep in mind that some other functionality might break because of this. You may want to add some additional conditionals.

  • Where can I set this code, can you specify it, in the function.php or template page? The reason I ask is that so many such links have been indexed in Google. I will be able to remove it from Google's indexing. But I don't want to re-index such links. Another problem that I am facing is with http iadm.edu.pk/?anyword, which will redirect to HTTPS and show the home page http links are also indexed in Google whereas i set my domain with https www. format.
    Apr 7, 2022 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.