Improving the Search URL Slug of a WordPress Site via cPanel #
Improving the Search URL Slug of a WordPress Site via cPanel, SEO-friendly URLs help with indexing, but the real secret to search engine ranking lies in the platform’s default search URL structure. We’ll demonstrate how cPanel users can enhance the search URL slug of any WordPress site (http://www.example.com/?s=search-term) to boost its overall SEO. Additionally, reliable web hosting is crucial for improving a website’s SEO rankings. When it comes to URLs, consider URL hosting plans that guarantee higher uptime, excellent security, 24/7 customer support, and more.
With a few tweaks, your search URL slugs can better align with your site’s permalink structure. We’ve discussed configuring the Functions File and modifying the .htaccess file. The goal is to transform the current search URL slug:
http://www.example.com/?s=search-term into http://www.example.com/search/search-term.
Simplify the Website's Function File #
1. Sign in to your user account on cPanel.
2. Navigate to the FILES section and click on File Manager.
The File Manager interface will appear.
3. Locate the functions.php file by following the path public_html>>wp-content >> themes.
4. Right-click on the functions.php file and choose Edit.
The file will open in the editor window.
5. Add the provided code at the end of the file.
6. Click Save Changes and then Close the editor.
This will optimize the structure of the search URL slug.
/** * Change search page slug. */ function wp_change_search_url() { if ( is_search() && ! empty( $_GET['s'] ) ) { wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); exit(); } } add_action( 'template_redirect', 'wp_change_search_url' );
Enhance Search URL Slug via .htaccess #
1. Sign in to your cPanel account.
2. Open File Manager and edit the .htaccess file.
3. Add this code at the bottom of the file:
# Change WordPress search URL slug RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC] RewriteRule ^$ /search/%1/? [NC,R,L]
4. Click Save Changes and Close the editor.
By using any of these methods, cPanel users can easily update the search URL slug of a WordPress site and enhance SEO.