首页 > 解决方案 > 使用 htaccess 将包含特定部分的所有页面重定向到主页

问题描述

最近我的网站被黑了,生成了大量的页面。它们中的大多数以 , 等字符串结尾?_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>

谢谢

标签: .htaccessredirectmod-rewriteurl-rewritingquery-string

解决方案


使用您显示的尝试/示例,请尝试遵循 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>

推荐阅读