2013-07-18 71 views
0

我想将404页的列表重定向到www.domain.com/news/为SEO的原因。htaccess重定向搜索特定的查询字符串,并删除

我成功地重定向像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相机连/ P =到/新闻/因为他们中的一些会重定向到一些特定的页面。

非常感谢。


行我想出了这两个

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 

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


我找到了答案饲料= 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); 

回答

0

OK,我想出了这两个

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)($|&) 

他们正在工作!


我找到了答案饲料= 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); 
0

你为什么不试试这个:

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

的代码,我想这一点,只是不工作,我也会尝试(P = 111 |(进料= RSS2&P = 123)),以避免混淆系统,但stll没有良好的反响。不管怎么说,还是要谢谢你。 –

+0

我更新了一下我的代码。再试一次。 –

+0

感谢您的帮助,但这些代码没有任何更改。 –

相关问题