【问题标题】:htaccess redirect search specific query strings and removehtaccess 重定向搜索特定查询字符串并删除
【发布时间】:2013-07-18 02:05:34
【问题描述】:

出于 SEO 原因,我想将 404 页面列表重定向到 www.domain.com/news/。

我使用以下代码成功重定向了 www.domain.com/news/?p=1234 和 www.domain.com/news/?p=111&replytocom=333 等页面:

RewriteCond %{QUERY_STRING} ^(p=1234|p=111)($|&) 
RewriteRule ^news/$ domain.com/news/ [L,R=301]

但是其中一些页面有非常奇怪的查询字符串,我不知道如何在 htaccess 中查询和删除它们。

www.domain.com/news/?p=12345;0;0;0;latestnews
www.domain.com/news/?feed=rss&p=123
www.domain.com/news/?p=123%3B0%3Blatestnews

我真的不想将所有带有 /?p= 的 url 重定向到 /news/,因为其中一些会重定向到某个特定页面。

提前非常感谢。


好的,我想出了这两个的解决方案

www.domain.com/news/?p=12345;0;0;0;latestnews
www.domain.com/news/?p=123%3B0%3Blatestnews

我只是在条件中添加 p=123;0;0;0latestnews,因为代码写得像这样

RewriteCond %{QUERY_STRING} ^(p=1234|p=111|p=123;0;0;0latestnews)($|&) 

他们正在工作!

仍在寻找应对方法

www.domain.com/news/?feed=rss&p=123

如果有人有任何解决方案,请告诉我!非常感谢!


我找到了 feed=rss&p=123 的答案,很抱歉我忘记提及我的网站是 wordpress 网站。

因此,浏览器似乎无法将此页面识别为 404,甚至无法识别我们服务器下的页面。该页面看起来像一个空的 RSS 页面。 所以我决定禁用 RSS,因为我并没有真正使用它,然后通过 PHP 进行重定向。 这是我的functions.php中的代码

function wp_disable_feed() { 
    header('Location: http://www.mysite.com/news/');
    //wp_die( __('Sorry, no feeds available, return to <a href="'. get_bloginfo('url') .'">homepage</a>') );
}
add_action('do_feed', 'wp_disable_feed', 1);
add_action('do_feed_rdf', 'wp_disable_feed', 1);
add_action('do_feed_rss', 'wp_disable_feed', 1);
add_action('do_feed_rss2', 'wp_disable_feed', 1);
add_action('do_feed_atom', 'wp_disable_feed', 1);

【问题讨论】:

    标签: .htaccess redirect query-string


    【解决方案1】:

    你为什么不试试这个:

    RewriteCond %{QUERY_STRING} ^(p=1234|p=111|p=123;0;0;0latestnews|feed=rss&p=123)
    RewriteRule ^news/$ http://domain.com/news/ [R=301]
    

    【讨论】:

    • 我试过这个,只是不工作,我也尝试 (p=111|(feed=rss2&p=123)) 以避免混淆系统,但仍然没有很好的响应。无论如何,谢谢。
    【解决方案2】:

    好的,我想出了这两个的解决方案

    www.domain.com/news/?p=12345;0;0;0;latestnews
    www.domain.com/news/?p=123%3B0%3Blatestnews
    

    我只是在条件中添加 p=123;0;0;0latestnews,因为代码写得像这样

    RewriteCond %{QUERY_STRING} ^(p=1234|p=111|p=123;0;0;0latestnews)($|&) 
    

    他们正在工作!


    我找到了 feed=rss&p=123 的答案,很抱歉我忘了说我的网站是 wordpress 网站。

    因此,浏览器似乎无法将此页面识别为 404,甚至无法识别我们服务器下的页面。该页面看起来像一个空的 RSS 页面。所以我决定禁用 RSS,因为我并没有真正使用它,然后通过 PHP 进行重定向。这是我的functions.php中的代码

    function wp_disable_feed() { 
        header('Location: http://www.mysite.com/news/');
        //wp_die( __('Sorry, no feeds available, return to <a href="'. get_bloginfo('url') .'">homepage</a>') );
    }
    add_action('do_feed', 'wp_disable_feed', 1);
    add_action('do_feed_rdf', 'wp_disable_feed', 1);
    add_action('do_feed_rss', 'wp_disable_feed', 1);
    add_action('do_feed_rss2', 'wp_disable_feed', 1);
    add_action('do_feed_atom', 'wp_disable_feed', 1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2014-02-02
      • 1970-01-01
      • 2012-08-16
      • 2014-11-11
      相关资源
      最近更新 更多