How to Modify the Search URL Slug Using .htaccess for a Better SEO Score

How to Modify the Search URL Slug Using .htaccess for a Better SEO Score

 

SEO is the most talked topic on the web right now. Everyone is trying to achieve something others don’t. You will be amazed to know that even the search results of your WordPress website play a vital role in SEO.

If you look at the pages and posts, you can find SEO-friendly URLs. Thanks to SEO plugins, which allow its user to leverage a website for a perfect SEO score.

In the last couple of years, people have started realizing how important it is to follow the latest Google trends. As you know, even the page loading time of a site impacts its SEO.

In today’s tutorial, you’re going to learn about changing the default search URL slug to an SEO-friendly slug without using any plugin.

As you have already read, we’re going to use the .htaccess file, but you should also know that the same task can be accomplished using the functions.php file.

But today, I am going to provide you with the .htaccess code.

A Step By Step Guide to Change the Default Search URL

By default, WordPress search URL isn’t SEO-friendly. Let me give you an example.

http://yoursite.com/?s=search-item

You can easily tell that such a URL isn’t understandable.

If you’re a regular WordPress user, you may already know how vital .htaccess is to a WordPress site. The file handles all the rewrite rules and many other concepts.

I hope you know how to edit .htaccess. There are two different ways. You can either use FTP or cPanel. In this tutorial, I am going to show you the cPanel method.

Even the cheapest web hostings allow access to cPanel.

Let’s start the process.

Step 1:

As usual, you need to login to your web hosting cPanel account and

look for the file manager
,  where all the data of your site is residing.

Most of the web hosting companies keep the file manager under the Files’ section. Even though you don’t have the reputed web hosting, you can still find the file manager.

Almost every reliable web hosting cPanel access.

Step 2:

Make sure you open the public_html directory because by default a home directory may open up.

Expand the public_html directory from the sidebar of cPanel

.

Step 3:

Now you can see all the files and folders of a WordPress site.

Scroll a bit, and you can find the .htaccess file

, if you don’t see it, you need to change the cPanel settings from the top-right corner.

Check the box to show hidden files for the chosen domain.

Step 4:

Refresh the page and seek for the .htaccess file. Right-click to edit

. You can also use the common Edit link from the main navigation menu.

Step 5:

A popup appears to confirm that you understand the meaning of editing such an important file.

Click on the Edit link to continue

.

Step 6:

A new tab opens up in the web browser where you can notice numerous coding lines.

Copy and paste the code in the file before #End WordPress

. Click on the Save Changes button from the top-right corner.

# Change the WordPress Search URL
RewriteCond%{QUERY_STRING} ?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]

Once you add it, the search URL becomes http://yoursite.com/search/search-query

Do You Think You Can Modify Search URL

Every time something new comes up, you may fret, and it’s obvious. But you should understand that WordPress keep evolving with time.

You need to be prepared for new challenges. Modifying the default search URL slug helps you improve the overall SEO of your site.

Conclusion

There are different methods to accomplish one task, and it’s always important to choose the convenient way. I hope it wasn’t difficult to add the code in .htaccess.

Follow the steps and within a few minutes, you can have an SEO-friendly search URL.

Check out these top 3 WordPress hosting services:

A2 Hosting
$1.95 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
  • Want to get top recommendations about best hosting? Just click this link!

How to Add Custom Code to Header and Footer Areas of a WordPress Website

The tutorial will have two methods of adding the custom code to the header and f
3 min read
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert

How to Secure the .htaccess File from Unauthorized Access

This guide will help you add one more security layer to your website by protecti
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Disable PHP Execution to Improve Website’s Security Using cPanel

This how-to guide will explain about restricting others from executing any malic
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Add Google Fonts to Your WordPress Website Without a Plugin

This is a how-to guide consisting of the code editing of the WordPress website t
3 min read
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top