Redirecting from osssearchresults.aspx

In SharePoint MOSS 2007, when you turn on the custom scope in site collection’s “Search Settings”, most of search results will be displayed at /SearchCenter/Pages/results.aspx. The exceptions are at the contextual search (This site, This List: Documents etc) and it always displays the search result in OSSearchResults.aspx page, which you can not customize through web parts (as you can do with /SearchCenter/Pages/restuls.aspx). This trick seems works very well (original post here):

Open OSSearchResult.aspx in layout folder, and add this block:

<script language = “javascript”>
function getURLParam(strParamName){
var strReturn = “”;
var strHref = window.location.href;
if ( strHref.indexOf(“?”) > -1 ){
var strQueryString = strHref.substr(strHref.indexOf(“?”)).toLowerCase();
var aQueryString = strQueryString.split(“&”);
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + “=”) > -1 ){
var aParam = aQueryString[iParam].split(“=”);
strReturn = aParam[1];
break;
}
}
}
return unescape(strReturn);
}
var urlstring = ‘http://your site url/custom-search.aspx?k=’ + getURLParam(‘k’) + ‘&cs=’ + getURLParam(‘cs’) + ‘&u=’ + getURLParam(‘u’)

location.replace(urlstring);
</script>

I added right after the stylesheet block and I guess you can remove some un-used code block since this page will not be used at all.

About these ads
This entry was posted in Search and tagged . Bookmark the permalink.

4 Responses to Redirecting from osssearchresults.aspx

  1. Hello there.

    Thank you for the tip. A couple of comments though:
    #1: You should keep the parameter values as is when rebuilding the url or you may end up with incorrectly encoded URL. In other words, the line unescape(strReturn); is more harmful than helpful.
    (By the way, the proper way to decode url parameters is to use decodeUriComponent instead of unescape)
    #2: The code on your page is all formatted for pretty rendering but a copy and paste won’t work. The quotes (single and double) are converted into non-ascii symbols and as a results the page appears not to be working (IE does not even throw errors).

    Thanks,
    Tony.

  2. Mike says:

    The downside of editing the ASPX file in the _layouts folder is it will change the entire “This List”/ “This Site” scope URL to forward to one direction on the entire farm. I would like to be able to apply one site to forward to one search center and another forward to the other.. and not the entire farm. Have any ideas?

  3. calvin998 says:

    Mike, yes you can limit that just to your own site. Make a copy of the \layout folder and change the file in that new location, and point the virtual directory of /_layout of your site to that new location. That way your site has its own /_layout folder.

  4. Paul says:

    The downside is that this solution relies on customising a system page which will leave your installation in an unsupported state by Microsoft.

    It would be better if everyone filed this as a bug or feature request in the hope that it was rectified in the next service pack (along with a whole host of other bugs!).

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