Cloud Service >> Knowledgebase >> DirectAdmin >> How to Change a WordPress Site’s Search URL Slug via DirectAdmin?
submit query

Cut Hosting Costs! Submit Query Today!

How to Change a WordPress Site’s Search URL Slug via DirectAdmin?

In case you're operating on a WordPress site, you might find yourself occasioning a change in the search URL slug during this time. These are the keywords that directly relate to your website when doing a search on it. 

Such as, for instance, if your query URL is like “your site. A site is www.mysearchexam.com?s=query, you can rewrite it to give more details and call it www.detailsearch.com. Thus, space it out also rocks where the sense of space can be preserved and, at the same time, leads to a great user experience. 

Follow this step-by-step instruction where we designed it so you can easily change the search URL slug for your WordPress site by using the DirectAdmin interface.

What You Need Before You Start

Prior to beginning the instructions, confirm that you have the following:

Getting into DirectAdmin: It is necessary for you to be able to access your DirectAdmin control panel.

Permissions to alter files: Make sure you possess the authorization required to modify files.

Make a site backup: Always make a backup of your WordPress website before making any changes to prevent unintentional data loss.

Step 1: Log Into DirectAdmin

Logging into your DirectAdmin account is the first step. Typically, to do this, type yourwebsite.com:2222—where "yourwebsite.com" is your real domain name—into the address bar of your web browser. To gain access to the dashboard, enter your password and login.

Step 2: Access File Manager

After logging in, locate and click the "File Manager" button. This will lead you to the location of all the files on your website.

Step 3: Find the functions.php File

Go to the directory where you installed WordPress. Usually, this is located in the www or public_html folder. Go to wp-content > themes > your-active-theme to locate the folder for your active theme. Find the functions.php file in this directory.

Step 4: Edit the functions.php File

Open the functions.php file by right-clicking on it and selecting 'Edit'. Be careful here, as any incorrect edits can affect your site's functionality.

Step 5: Add the Custom Function

At the end of the file, add the following code snippet:

php

Copy code

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

This code changes the default search URL slug from ?s to /search/. Make sure to save the changes after adding the code.

Step 6: Update Your .htaccess File

Now, you need to ensure that the server understands this new URL structure. Return to the File Manager and locate the.htaccess file in the same directory as your WordPress installation to do this. Launch it, then append the subsequent line to the end of the file:

ruby

Copy code

RewriteRule ^search/(.*)$ ?s=$1 [L,QSA]

This line tells the server to internally redirect any requests from /search/query to ?s=query, making the new URL functional.

Step 7: Save and Test

Save the changes in the .htaccess file and close the editor. Now, go to your website and try using the search function with the new URL slug (e.g., yourwebsite.com/search/test-query). If everything is set up correctly, it should work just like it did with the old URL slug.

Final Thoughts

Congratulations! The search URL slug of your WordPress site was changed through DirectAdmin using the first method. In addition to this, you will own a clean-looking url, not only that, but it will also improve the user experience on your site. Don’t forget to clear your website’s cache when working with caching plugins to see the changes start taking effect immediately.

The fear of changing technical settings can be quite challenging, especially if you are not a technical person. But, with a few easy steps and a backup, you will surely be more confident to make adjustments to your site. If by any chance you have any trouble, then contact an expert or the customer support team of your hosting service to get more information on how to solve such problems. For more information-contact our hosting team today!

 

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!