2

My site got hacked last month and a lot of PDFs were added in Google ending in /index.php?voxter.pdf&gpvoq=1&static=1866.

I have cleaned the site but now these pages are redirecting to home page instead of returning error 404. As a result, these pages are still there in Google Search results. Whenever I use /index.php?voxter.pdf&gpvoq=1&static=1866 this at any WordPress site, it shows homepage only.

But my question is why Google is showing these non existent pages in search results?

One argument can be Gogle previously indexed these pages so it wont remove it from results till they return error 404. How can I make these pages to return error 404?

6
  • You could use canonical links which is always highly recommended which would resolve the issue in time. Commented Jul 9, 2015 at 7:57
  • There are thousands and thousands of such pages due to hack. ?voxter.pdf&gpvoq=1&static=1866 is just a example. gpvoq=1&static=1866 is this, number changes and thus, adding the pages
    – Mac Brian
    Commented Jul 9, 2015 at 7:59
  • Use canonical, it'll get rid of those in no time... it tells Google the correct URL, so if you have a page that is accessible via ?string1 ?string2 etc it will tell Google which page is the master, and ignore the rest. Commented Jul 9, 2015 at 8:01
  • So to which page should I add canonical? I am sorry I am not that technical guy.
    – Mac Brian
    Commented Jul 9, 2015 at 8:04
  • Presumably these PDFs should not and do not exist on your site? I think perhaps @Simon is assuming that these PDFs exist on the site but should be accessible by a different URL?
    – MrWhite
    Commented Jul 9, 2015 at 10:39

3 Answers 3

1

Wordpress themes support 404 page. You can see the full documentation here https://codex.wordpress.org/Creating_an_Error_404_Page

It is also useful to display proper http status code 404 while displaying 404 error page.

0

I know this question was asked many years ago but it looks like it was never properly answered. I wrote a guide on how to force a 404 error page in WordPress.

So for this question specifically you could use some code that looks like this:

function wpexplorer_force_404_error() {
    if ( is_front_page() && ! empty( $_GET ) ) {
        global $wp_query;
        $wp_query->set_404();
        status_header( 404 );
    }
}
add_action( 'wp', 'wpexplorer_force_404_error' );

This code will display a 404 page whenever a query string is added to the homepage.

Important: I would NOT recommend using this code, instead what you may want to do is 301 redirect any homepage URL's that contain a query string back to he homepage.

Example:

add_action( 'template_redirect', function() {
    if ( is_front_page() && ! empty( $_GET ) ) {
        wp_safe_redirect( esc_url( home_url( '/' ) ), 301 );
        exit;
    }
} );
-1

There are a range of plugins you can add to your WordPress installation which will trigger a 404 error instead of redirecting to the homepage when a page could not be found. I am not going to recommend one as ProWebmasters is not designed for recommending software or plugins but what I will do is give you this link http://www.lmgtfy.com/?q=wordpress+hard+404+plugin which will take you the Google search for hard 404 plugins for WordPress.

Your Answer

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

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