1

After I recovered Drupal 7 site from malware attack I end up with lot of links pointing to (previously) spam content like this:

https://www.example.com/lshop/puma-rihanna-c-449/?zenid=id311p8tc67mbnbu8gb17d1uf1
https://www.example.com/eshop/nike-start-l-259/
https://www.example.com/eshop
https://www.example.com/fshop/adidas-maradona-k-149/

Content was removed but backlinks left. I was able to compose this rules in .htaccess redirecting malicious backlinks to 410 Gone status page:

<IfModule mod_rewrite.c>
redirect 410 /ashop/
redirect 410 /ashop

redirect 410 /bshop/
redirect 410 /bshop

redirect 410 /cshop/
redirect 410 /cshop

redirect 410 /eshop/
redirect 410 /eshop

redirect 410 /fshop/
redirect 410 /fshop

redirect 410 /ishop/
redirect 410 /ishop

redirect 410 /lshop/
redirect 410 /lshop

redirect 410 /oshop/
redirect 410 /oshop

redirect 410 /pshop/
redirect 410 /pshop
</IfModule>

List can be longer. How to catch - using regex - pattern "backslash after domain + one letter + word 'shop' optionally continuing with backslash" and redirect such link to 410 on server level befor it touch Drupal?

I tried following patterns based on these two answers but without success:

redirect 410 /[a-z]shop/
redirect 410 /^([a-zA-Z])shop/
redirect 410 ^\/([a-z])(shop)\/(.*)$
redirect 410 ^[a-z]shop+$
1

redirect is a mod_alias directive (not mod_rewrite) and does not accept a regex. Both the answers you link to use the mod_rewrite RewriteRule directive.

Note that in .htaccess the RewriteRule pattern does not match against the slash at the start of the URL-path (unlike a mod_alias Redirect or RedirectMatch directive).

For example:

RewriteRule ^[a-z]shop($|/) - [G]

The above matches either a request for /xshop or /xshop/<anything> (where x is any lowercase letter) and serves a 410 Gone.

This needs to go near the top of your .htaccess file and the <IfModule> wrapper is not required.

| improve this answer | |
  • 1
    So I have been mixing 2 things. RewriteRule works. Thank you for help @MrWhite – Jasom Dotnet Apr 28 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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