Knowledge Base
MilesWeb / cPanel, How-Tos, WordPress FAQ

How to Improve the Search URL Slug of a WordPress Site via cPanel?

Approx. read time : 3 min

SEO-friendly URLs are beneficial for indexing. But, the secret to search engine ranking lies in the platform’s default search URL structure. We will show you how cPanel users can improve the search URL slug of any WordPress site (http://www.example.com/?s=search-term) to raise its overall SEO status.

With a few adjustments, your search URL slugs will be more in tune with your site’s permalinks format. We have talked about configuring the Functions File and changing the .htaccess file. The idea is to change the site’s present search URL slug:
http://www.example.com/?s=search-term into this http://www.example.com/search/search-term.

Table of Contents
Did you know!

Configuring your WordPress website with SEO-friendly URLs will only index posts and pages which, is not enough to improve SEO ranking. The structure of these search URLs should also seem genuine and easy to read for search engine crawlers to optimize the search pages for search engines.

 

Rearrange Site’s Function File

1. Log in to your user account of cPanel.

2. Go to the FILES section and click on File Manager.

The File Manager interface will open.

3. Browse functions.php file by following the path public_html>>wp-content >> themes.

4. Right-click the functions.php file and select Edit.

The file will open in the editor window.

5. Paste the given code at the end of the file.

/**
* 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' );

6. Click Save Changes and Close the editor.

It should change the structure of the search URL slug to the most optimum level.

Improve Search URL Slug with .htaccess

1. Log in to your cPanel account.

2. Open File Manager and edit the .htaccess file.

Note: You can refer to this article to help you understand How To Edit A .htaccess File Through The cPanel File Manager?

3. Paste this code at the end 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 applying any one of the methods, cPanel users can effectively amend the search URL slug of a WordPress site and improve the SEO.

P.S.

Users can also use the FTP client to download the functions.php or .htaccess file, edit and then reupload them on the server.

Prasad is a business grad specialized in Marketing. He has garnered experience as a technical content writer and a digital marketer that he brings out in his work. He likes reading classics and travel in his free time.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna