.htaccess:将除少数URL外的所有URL重定向到主页

.htaccess:将除少数URL外的所有URL重定向到主页,.htaccess,redirect,.htaccess,Redirect,我已经从一次黑客攻击中恢复过来,在谷歌索引中,我的网站上有数千个垃圾赌场链接 我想将除合法页面以外的所有URL重定向到主页 这就是我现在拥有的: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/(dienstverlening|starters|a

我已经从一次黑客攻击中恢复过来,在谷歌索引中,我的网站上有数千个垃圾赌场链接

我想将除合法页面以外的所有URL重定向到主页

这就是我现在拥有的:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(dienstverlening|starters|accountancy|administratie|belastingen|salarisadministratie|contact|over-ons|algemene-voorwaarden)
RewriteRule ^ [R=301,L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}^/(迪恩斯特维列宁|初学者|会计|行政|贝拉斯汀|萨拉斯行政|联系|过ons |阿尔杰梅内·沃沃登)
重写规则^[R=301,L]

如何将所有其他URL重定向到.htaccess中的主页?

您的重写规则中缺少一个目标。Apache在解析方面有点笨,所以它假设
[R=301,L]
是您想要重定向到的地方。尝试在该规则中添加
/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(dienstverlening|starters|accountancy|administratie|belastingen|salarisadministratie|contact|over-ons|algemene-voorwaarden)
RewriteRule ^ / [R=301,L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}^/(迪恩斯特维列宁|初学者|会计|行政|贝拉斯汀|萨拉斯行政|联系|过ons |阿尔杰梅内·沃沃登)
重写规则^/[R=301,L]

谢谢您的回答。这捕获了谷歌索引中的垃圾邮件链接,但我得到了一个错误“这个页面没有正确重定向”。我们还需要添加其他内容吗?嗨,John,还有什么我们可以尝试的吗?@Forza您可以尝试将
index.php
作为URI长列表的一部分,也许就在上面包含
RewriteCond%{REQUEST\u URI}^/$不幸的是,这不起作用。添加
RewriteCond%{REQUEST\u URI}后^/$重定向完全停止工作,我再次获得赌场页面:(在这里你可以看到我试图重定向的内容:(所有那些/21、/bonus1和/58 URL和/sitemap_2.php等)