大网数据广告活动
网站运营与故障问答

.htaccess redirect to "410 Gone" status for URLs containg one letter + word "shop" after domain

· 52CE 我爱测

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.exampl…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。