How To

How to change WordPress default search slug [easy method 2023]

There are several reasons why you want to change the default WordPress default slug URL. The most important reason could be excluding it from Google Adsense ad requests to avoid policy violations.

Google Adsense doesn’t allow users to exclude pages that are query parameters such as the WordPress search slug ?s=.

So how to change the default search slug URL in WordPress?

You can easily change the default search slug from ?s= to /search/ by adding the following code snippet to your htaccess file:

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

Update the robots.txt file to disallow the new slug from being crawled by adding the following to your robots.txt file via Yoast -> tools – edit files or from your file manager.

Disallow: /search/

And also, now you can ask Google Adsense to exclude search pages from being severed with ads:

Go to your Adsense account –> Ads –> Click on the edit icon next to your domain name –> this will open the auto ads page, now from the right sidebar, select exclude pages –> add the desired pages –> done.

Google Adsense exclusionsThis will prevent Google Adsense from serving empty search pages with ads, protecting your site from violating Google Adsense policies.

Related Articles