Last update at :2024-07-09,Edit by888u
By default when we use WordPress, when we search for keywords in the site, we see the search result is "https://www.cnwper.com/?s=Maizi". If you want better SEO effect It would be better if it is "https://www.cnwper.com/search/search term". How to achieve these effects?
There are 2 methods available here:
1. Function code implementation
//Modify the URL structure of the search results page function wpkj_change_search_url_rewrite() { if ( is_search() && ! empty( $_GET['s'] ) ) { wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); exit(); } } add_action( 'template_redirect', 'wpkj_change_search_url_rewrite' );
Here we add the code to Functions.php.
2. Apache pseudo-static settings
# Modify WordPress search results page URL RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC] RewriteRule ^$ /search/%1/? [NC,R,L]
If we are using a LAMP environment, we can use .htaccess to add pseudo-static implementation.
Recommended site searches: Chinese domain name fees, all-purpose virtual host, vps virtual host domain name search, top ten server brand rankings, website registration prices, overseas virtual host space, domain name registration, virtual space host, mobile agent IP,
p>
发表评论