How To Change WordPress Search Base Rewrite URL


You can change default WordPress search result URL from ?s= into /search/ with many methods. For some reason you want to change your default search permalink into another words. Now i will share how to changing /search/ permalink into another word for example: /result/ or /list/ or anything you want.

There are 3 alternate way to change, choose only one of them:

1. Using Plugins

– Install Search Permalink Plugins
– Open and edit file: /wp-include/rewrite.php
– Find line:

1 var $search_base = 'search';

change into anything permalink you want, for example you want change into /result/ so update that line:

1 var $search_base = 'result';

– Close and save rewrite.php
– Go to Permalinks menu in wp-admin and click Save Changes
– Now your search permalinks has change into something like: http://yourdomain/result/keyword+to+seacrh/

2. Using .htaccess

– Open and edit .htaccess, on very top insert this line:

1 Options +FollowSymLinks
2 RewriteEngine On
3 RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(#[^?&\ ]*)?\?([^&\ ]*&)?s=([^&\ ]+)[^\ ]*\ HTTP/
4 RewriteRule ^$ http://www.yourdomain/result/%3? [R=301,L]

So you will get /result/ search permalinks
– Open and edit file: /wp-include/rewrite.php
– Find line:

1 var $search_base = 'search';

change into anything permalink you want, for example you want change into /result/ so update that line:

1 var $search_base = 'result';

– Close and save rewrite.php
– Go to Permalinks menu in wp-admin and click Save Changes
– Now your search permalinks has change into something like: http://yourdomain/result/keyword+to+seacrh/

3. Using PHP Redirect

– Open and edit search.php file in your template, on very top insert this code:

1 <?php
2 if($_GET['s']!=''){
3 $change = array('+',' '); //mark plus and space
4 $searchredirect = get_settings('home') . '/result/' . str_replace($change, '-' ,$_GET['s']). ''; //plus and space in URL will replaced with dash
5 header("HTTP/1.1 301 Moved Permanently");
6 header( "Location: $searchredirect" );
7 }
8 ?>

So you will get /result/ search permalinks
– Open and edit file: /wp-include/rewrite.php
– Find line:

1 var $search_base = 'search';

change into anything permalink you want, for example you want change into /result/ so update that line:

1 var $search_base = 'result';

– Close and save rewrite.php
– Go to Permalinks menu in wp-admin and click Save Changes
– Now your search permalinks has change into something like: http://yourdomain/result/keyword-to-seacrh/

Source ninoholic.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s