问题原文
原帖链接 · Jasom Dotnet · CC BY-SA 4.0
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+$
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
