我正在尝试更改我的自定义搜索url以实现SEO目的。我找到一篇关于如何改变的文章mydomain.com/?s=query
到mydomain.com/search/query
. 但是,我更喜欢自定义搜索url,例如mydomain.com/something/query
.
这是否可以实现?
谢谢你的帮助!
我正在尝试更改我的自定义搜索url以实现SEO目的。我找到一篇关于如何改变的文章mydomain.com/?s=query
到mydomain.com/search/query
. 但是,我更喜欢自定义搜索url,例如mydomain.com/something/query
.
这是否可以实现?
谢谢你的帮助!
这很简单。只需添加此挂钩template_redirect
操作,它会将您的搜索查询重定向到nice url:
function wpse8170_search_url_redirect() {
if ( is_search() && !empty( $_GET[\'s\'] ) ) {
wp_redirect( home_url( "/something/" . urlencode( get_query_var( \'s\' ) ) ) );
exit;
}
}
add_action( \'template_redirect\', \'wpse8170_search_url_redirect\' );
添加到您的.htaccess
文件:# search redirect
# this will take anything in the query string, minus any extraneous values, and turn them into a clean working url
RewriteCond %{QUERY_STRING} \\\\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]
是否有办法在上显示所有搜索结果search.php?实际上,它只显示10个结果(如WordPress settings > general).