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

What do I put in htaccess to create a 410 error page when a URL parameter is present?

· 52CE 我爱测

I tried to create a 410 error page but realized that I actually created a 302 redirect to a 410.php page. Instead I want to use a 410 error to block out an infinite number of dynamically created pages that are being indexed by Go…

问题原文

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

I tried to create a 410 error page but realized that I actually created a 302 redirect to a 410.php page. Instead I want to use a 410 error to block out an infinite number of dynamically created pages that are being indexed by Google. I have about 30k internal links that are indexed on Google thanks to a faulty internal search engine:

  • http://www.example.com/?searchkey=1_q
  • http://www.example.com/?searchkey=2ak - (etc... goes on for 30k times)

What should I write in htaccess to block anything with this "searchkey" parameter such that a 410 error page is served? (I'm not a programmer, so I would appreciate a simplified response.)

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 3.0

You could do this using the following rewrite rule in .htaccess:

RewriteEngine on 
RewriteCond %{QUERY_STRING} searchkey
RewriteRule .* - [G,L]
  • .* means that it will do this for any URL on your site (as long as the condition of having "searchkey" in the query string is met)
  • - means to leave the URL alone and not change it
  • G means "Gone" -- send the 410 status
  • L means "Last" -- so that no other rewrite rules are executed

Since you have a custom 410 gone page, you could also use the following .htaccess directive to show it instead of the default 410 gone error page:

ErrorDocument 410 /410.php

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

资料来源与适用范围

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

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

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