【问题标题】:Redirect if certain query term in WordPress Search如果 WordPress 搜索中的某个查询词,则重定向
【发布时间】:2016-09-05 11:51:21
【问题描述】:

我有一个 WordPress 网站,如果用户使用 WordPress 搜索功能搜索特定术语,我想重定向他们。

如果用户在搜索框中输入“鼠标”,WordPress 会打开这个页面:

example.com/?s=mouse

并且只有当查询词是“鼠标”时,我才想将用户重定向到:

example2.com/bad.htm

如果查询词是另一个词(例如 cat),只需使用默认行为(显示搜索结果)。

我已尝试使用 .htaccess 进行默认重定向:

Redirect 301 /?s=mouse http://www.example2.com/bad.htm

但我仍然看到/?s=mouse 页面并且我没有被重定向。

有什么解决办法吗?

【问题讨论】:

    标签: php wordpress .htaccess redirect


    【解决方案1】:

    试试下面的规则,

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^(s=mouse|s=mouse\+dog)$
    RewriteRule ^ http://example2.com/bad.htm? [R=301,L]
    

    【讨论】:

    • @starkeen 如果我想使用 2 个替代术语,您将如何编辑它:如果查询术语是“mouse”或“mouse+dog”,则重定向到 example.com/bad.htm
    • 在这种情况下,您只需将条件模式更改为 ^s=(mouse|mouse\+dog)$
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多