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

Send "410 Gone" response for URLs that are a "c" or "g" followed by digits

· 52CE 我爱测

Is there anything i can use in my htaccess to send 410 code to all the links but not some links ? Example: I would like to 410 this urls (List is about 40k links) www.example.com/c1 www.example.com/c2 www.example.com/c3 www.examp…

问题原文

原帖链接 · Sahil Moldharia · CC BY-SA 3.0

Is there anything i can use in my htaccess to send 410 code to all the links but not some links ?

Example:

I would like to 410 this urls (List is about 40k links)

www.example.com/c1
www.example.com/c2
www.example.com/c3
www.example.com/c4
www.example.com/g1
www.example.com/g2
www.example.com/g3
www.example.com/g4
and so one....

but this links should not come 410, anything that start with c or g

Like:

www.example.com/categories/
www.example.com/concreate/
www.example.com/colombs/

Right now I am using this code in my .htaccess file but this also giving 410 to above links.

RewriteEngine On
RewriteCond %{QUERY_STRING} c
RewriteRule .* - [G,L]
ErrorDocument 410 default

Any help would be much appreciated.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

RewriteCond %{QUERY_STRING} c

Not sure why you are referencing the QUERY_STRING here? Your URLs don't appear to contain a query string?

It looks like the URLs you want to block start with a c or g and followed by a digit (I'll assume 1 or more digits). In which case, try something like the following:

RewriteEngine On
RewriteRule ^[cg]\d+$ - [G]

No need for the L flag with G.

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

资料来源与适用范围

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

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

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