.htaccess-仅在主页上从URL中删除参数

发布于 2025-01-27 04:28:10 字数 412 浏览 1 评论 0原文

我在某些子页面上使用参数,但是Google出于某种原因在主页URL中索引它们。

我如何在.htaccess仅用于主页中删除它们?

删除?a = 123在这里:

  • example.com/?a=123(结果:example.com

不要在此处删除它:

  • example.com/subpage/event.php?a=123

我找到了这个,但是我不知道如何仅将其应用于主页:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?

I am using parameters on some subpages, but google index them in the search results for some reason in the homepage URL.

How can I please remove them in .htaccess only for homepage?

remove ?a=123 here:

  • example.com/?a=123 (result: example.com)

don't remove it here:

  • example.com/subpage/event.php?a=123

I found this, but I don't know how to apply it only for homepage:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝有风,海豚有海 2025-02-03 04:28:11

使用以下方法:

RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^/?$ / [R=301,L,QSD]
  • %{query_string}。表示“ Query String包含至少一个字符”
  • ^/?$是“仅主页” - IE仅URL路径由可选的斜杠
  • [r = 301]重定向请求(更改URL)
  • [l]是最后一个重写规则,以便以后不会与之冲突一个
  • [QSD]是“ Query String delete”,因此重写不会尝试将查询字符串附加到重定向

Use this:

RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^/?$ / [R=301,L,QSD]
  • %{QUERY_STRING} . means "query string contains at least one character"
  • ^/?$ is "just the home page" -- ie the URL path only consists of an optional slash
  • [R=301] Redirects the request (to change the URL)
  • [L] is the last rewrite rule so that it doesn't conflict with later ones
  • [QSD] is "query string delete" so that rewrite doesn't try to append the query string to the redirect
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文