Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
in Q2A Core by
edited by
If anybody want to redirect error404 to a search page, then here is a trick for you.

I have recently changed my blog to a Q2A site. But there was a problem : Site was already indexed by gooogle and there are many pages of my site are at the top of google search. So, I change my site to Q2A then, its not possible to keep same link as my previous script. As a result my site ranking and visitors will decrease.

So, I thought, Insted of sending user to a error404 page why not redirect them to a search page.

yeak!!! sounds intersting laugh

I did this:

Simply replace whole code of


with this one:


        copyright was removed cuz i m not able to post more then 8000 chr

        if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
            header('Location: ../');

        require_once QA_INCLUDE_DIR.'qa-app-format.php';
        require_once QA_INCLUDE_DIR.'qa-app-options.php';
        require_once QA_INCLUDE_DIR.'qa-app-search.php';

    //    Perform the search if appropriate

        //    Pull in input parameters
            $urlfor    =    strtolower($_SERVER['REQUEST_URI']);
            $urlfrom404 = rtrim($urlfor,"/");
            $tokens = explode('/', $urlfrom404);
            $keys = array_keys($tokens);
            $last = end($keys);
            $removeHyphen = strtr($tokens[$last], '-', ' ');

            $count=2*(isset($display) ? $display : QA_DB_RETRIEVE_QS_AS)+1;
                // get enough results to be able to give some idea of how many pages of search results there are
        //    Perform the search using appropriate module

            $results=qa_get_search_results($inquery, $start, $count, $userid, false, false);

        //    Count and truncate results
            $results=array_slice($results, 0, $pagesize);
        //    Retrieve extra information on users    
            foreach ($results as $result)
                if (isset($result['question']))
        //    Report the search event
            qa_report_event('search', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array(
                'query' => $inquery,
                'start' => $start,

    //    Prepare content for theme


            if (count($results))
                $qa_content['title']=qa_lang_html_sub('main/results_for_x', qa_html($inquery));
                $qa_content['title']=qa_lang_html_sub('main/no_results_for_x', qa_html($inquery));
                'tags' => 'METHOD="POST" ACTION="'.qa_self_html().'"',

                'hidden' => array(
                    'code' => qa_get_form_security_code('vote'),
            foreach ($results as $result)
                if (!isset($result['question'])) { // if we have any non-question results, display with less statistics

            foreach ($results as $result) {
                if (isset($result['question']))
                    $fields=qa_post_html_fields($result['question'], $userid, qa_cookie_get(), $usershtml, null, $questionoptions);
                elseif (isset($result['url']))
                        'what' => qa_html($result['url']),
                        'meta_order' => qa_lang_html('main/meta_order'),

                    continue; // nothing to show here

            $qa_content['page_links']=qa_html_page_links(qa_request(), $start, $pagesize, $start+$gotcount,
                qa_opt('pages_prev_next'), array('q' => $inquery), $gotcount>=$count);
            if (qa_opt('feed_for_search'))
                    'url' => qa_path_html(qa_feed_request('search/'.$inquery)),
                    'label' => qa_lang_html_sub('main/results_for_x', qa_html($inquery)),

            if (empty($qa_content['page_links']))


        return $qa_content;

        Omit PHP closing tag to help avoid accidental output

here is demo:

Q2A version: 1.6
Update: Google loop was caused by my server handling URLs with %3F.

1 Answer

+1 vote
[05-Mar-2013 10:23:06] PHP Fatal error:  Call to undefined function  qa_get_form_security_code() in /qa-include/qa-page-not-found.php on line 94

What/Where is qa_get_form_security_code() ?
Which version you are using?? is it 1.6 ?? my code is for 1.6dev. If you are using 1.6 then I will check it
I am using 1.5.4, okay, then I should check the source code of 1.6...
Iam using 1.6.2 and getting the same error
Fatal error: Call to undefined function qa_get_form_security_code() in /qa-include/qa-app-q-list.php while using twitter bootstrap theme