Lawrence
Lawrence

Reputation: 3

Want to throw a 404 Error when URL contains a certain string

I recently had a pharma attack on my site and it's clean (at least as far as I can tell) however some URLs still exist off my page that have "bm9iz=" in the URL somewhere which all are somehow pointing to the main page (index.php). I don't know how the redirection is happening or where so I figure I can just create a rule that 404s any URL that contains the string "bm9iz=".

Some examples:

[www.nobenational.org/mcgill/members/?bm9iz=712730][1]

[www.nobenational.org/mcgill/events/?archive=1&bm9iz=460030‎][2]

[www.nobenational.org/mcgill/home.php?bm9iz=50000][3]

If you Google the following you will see why I want to get rid of these: "site:nobenational.org/mcgill viagra OR cialis"

Thanks!

Upvotes: 0

Views: 1616

Answers (3)

anubhava
anubhava

Reputation: 785008

Stick this rule as your first rule in your DocumentRoot/.htaccess:

RewriteEngine On

# If URI or QUERY_STRING has this bm9iz= word then make it forbidden (403)
RewriteCond %{THE_REQUEST} bm9iz=
RewriteRule ^ - [F]

Upvotes: 1

Joshua Bixler
Joshua Bixler

Reputation: 531

I don't think your issue is on your side. I think it might be because Google caches your pages.

If you do the search and click cache, you will see the results are coming from almost a month ago. Now if you just found this content on you site and just removed it, Google will take a while to change it cache.

You can request to clear all cache or recrawl your site. https://support.google.com/webmasters/answer/1663691?hl=en https://support.google.com/webmasters/answer/1352276?hl=en

Upvotes: 1

rodix
rodix

Reputation: 425

If you are using the Apache Web Server I recommend you mod_rewrite module, it will give you a better performance compared with anything that you can write on PHP.

Here is the documentation: http://httpd.apache.org/docs/2.2/rewrite/intro.html

The statement on the htconf to reply a forbidden header should be something like

RewriteRule bm9iz /403.html [NC,L,F]

Hope it helps.

Upvotes: 1

Related Questions