如何重定向查询字符串与破折号url使用htaccess


How to redirect query string with dash url using htaccess

如何重定向https://xyz.com/ceoblog/?tag=real-estate-assistant&paged=2到https://xyz.com/ceoblog/

我已经尝试了所有可能的解决方案,但无法重定向。

我如何做到这一点?

Thanks in advance

这个htaccess规则检查ceoblog上的任何查询字符串并重定向到ceoblog/

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^ceoblog(/?)$ /ceoblog/? [R=301,L]

然而,查看查询字符串将阻止分页和标签过滤器正常工作-也就是说,您将只停留在一个页面。

有几个可能的解决方案

  1. 如果您希望存储查询字符串数据,然后只是重定向到没有查询字符串,您可以在php脚本中这样做:

if(count($_GET)) {
    $mydata = $_GET;
    // do stuff with $data, like store it or something
    header("location: /ceoblog");
} else {
    // do other stuff
}

  1. 如果你只是想重定向,一个简单的301重定向在htaccess规则将完美地工作在这里