Jump to content


* * * * * 1 votes

Change Default Wordpress Search Base Rewrite Url

wordpress search rewrite

  • Please log in to reply
2 replies to this topic

#1 nirajan

nirajan

    Administrator

  • Administrators
  • 132 posts

Posted 13 December 2011 - 02:18 PM

IF you are wondering on changing default search base rewrite url of your WordPress blog, 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. Edit Rewrite.php

- Open and edit file: /wp-include/rewrite.php
- Find line:
var $search_base = 'search';
change into anything permalink you want, for example you want change into /result/so update that line:
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.co...search-keyword/
2. Using .htaccess

- Open and edit .htaccess, on very top insert this line:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(#[^?&\ ]*)?\?([^&\ ]*&)?s=([^&\ ]+)[^\ ]*\ HTTP/
RewriteRule ^$ http://www.yourdomain/result/%3? [R=301,L]
3. Using PHP Redirect

- Open and edit search.php file in your template, on very top insert this code
<?php
if($_GET['s']!=''){
$change = array('+',' '); //mark plus and space
$searchredirect = get_settings('home') . '/result/' . str_replace($change, '-' ,$_GET['s']). ''; //plus and space in URL will replaced with dash
header("HTTP/1.1 301 Moved Permanently");
header( "Location: $searchredirect" );
}
?>



So you will get yourdomain.com/result/ search permalinks

#2 madisonbrock

madisonbrock

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 19 December 2011 - 06:15 AM

This is a php code. I know something about php. It is a web designing language easy to learn and implement further. I am a java developer so I know some syntax in the this code.please tell me the output...?

#3 nirajan

nirajan

    Administrator

  • Administrators
  • 132 posts

Posted 22 December 2011 - 05:04 PM

View Postmadisonbrock, on 19 December 2011 - 06:15 AM, said:

This is a php code. I know something about php. It is a web designing language easy to learn and implement further. I am a java developer so I know some syntax in the this code.please tell me the output...?

This code is for Wordpress ,
Output :
http://www.yourdomain/result/searchquery






Also tagged with one or more of these keywords: wordpress, search, rewrite