【问题标题】:Redirect all pages containing a particular part to home using htaccess使用 htaccess 将包含特定部分的所有页面重定向到主页
【发布时间】:2021-09-09 17:01:11
【问题描述】:

最近我的网站被黑了,生成了大量页面。它们中的大多数以?_t=77?_t=97?_t=56 等字符串结尾。基本上,?_t= 部分在所有这些字符串中都很常见。

如何创建 .htaccess 规则以将所有带有?_t= 的链接重定向到主页?

我已经创建了一些重定向:

<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>

谢谢

【问题讨论】:

  • 请在您的问题中添加您尝试过的 htaccess 规则文件,谢谢。
  • 您的网站是否已有来自 CMS 或类似文件的 .htaccess 文件?发布它。
  • 抱歉,但在 Stack Overflow 上,强烈建议您展示您的努力(尝试过的代码没有对错),所以请编辑您的代码。一旦你编辑它,我就可以添加我的答案。
  • @RavinderSingh13 我已经更新了帖子
  • @heyitsritesh,谢谢你这样做,我现在添加了一个答案,你可以测试它,我们可以在答案的 cmets 部分讨论它,干杯。

标签: .htaccess redirect mod-rewrite url-rewriting query-string


【解决方案1】:

根据您显示的尝试/示例,请尝试遵循 htaccess 规则。请确保在测试您的 URL 之前清除您的浏览器缓存。

<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.

Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>

【讨论】:

  • 仅供参考:正如我显示的代码的 cmets 部分所述,这是考虑到您的主页是由后端的 index.php 提供的。如果不是,请确保将您的主页服务规则置于我发布的规则之下。
  • 您无法匹配 RewriteRule 中的查询字符串。它必须在 RewriteCond %{QUERY_STRING} _t= 中匹配,后跟 RewriteRule
  • @RavinderSingh13,这次效果很好!非常感谢 :) 非常感谢您的帮助、支持和时间。
  • 感谢@MichaelBerkowski 的帮助:)
  • @heyitsritesh,欢迎您。欢呼和快乐的学习:)
猜你喜欢
  • 1970-01-01
  • 2022-06-30
  • 2012-12-10
  • 1970-01-01
  • 2012-10-29
  • 2016-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多