htaccess重定向搜索特定的查询字符串并删除



出于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

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

提前非常感谢。


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

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

我只是加上p=123;0;0;0最新消息处于状态,因为代码写得像

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进行重定向。这是我的函数中的代码。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);

为什么不试试这个:

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

好吧,我为这两个想出了一个解决方案

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

我只是加上p=123;0;0;0最新消息处于状态,因为代码写得像

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

他们正在工作!


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

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

最新更新