正则表达式将任何以 ?layout=mobi 或 ?layout=full 结尾的 url 重定向到主页

Regex to redirect any url ending in ?layout=mobi or ?layout=full to homepage

将我的站点更改为 wordpress。过去有移动和完整站点选项,其中 ?layout=mobi 或 ?layout=full 会调用这些文件。

例如,现在在 WMT 中收到很多 404。com/page1。html?layout=mobi

我正在寻找正则表达式来将所有以 ?layout=full 或 ?layout=mobi 结尾的 404 重定向到网站的主页,这样这些 404 就不会阻塞我的 WMT。

谢谢

尝试这种方式,在应用 RewriteRule 重定向到您的主页

之前先检查 QUERY_STRING 上的 RewriteCond
RewriteEngine On
# Check if the query string contains layout=mobi OR layout=full
RewriteCond %{QUERY_STRING} ^(layout=mobi|layout=full)$
RewriteRule ^example.com/page1.html$ http://www.example.com/ [R=301,L]