I know I am answering this quite late. However, if there is someone out there who is looking for the solution, this might help them. ( Version Q2A 1.7)
Here, below steps need to follow.
1) From admin dashboard: General -> URL Structure select the 1st Option.
2) Change the .htaccess file with below code.
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
3) You need to handle incoming request + all the rendered URL in pages, sitemap, canonical URL, etc should be changed to the new format: <root_category>/<sub_category>/<question-id>/<question-title>. Create a plugin under qa-plugin folder (refer the url for how to create a plugin: http://docs.question2answer.org/plugins/overrides/). Following are the method overrides that need to be added in the plugin:
<?php
if ( !defined( 'QA_VERSION' ) ) { // don't allow this page to be requested directly from browser
exit;
}
/*
Handles the additional request format:
<root_category>/<sub_category>/<question-id>/<question-title>
Base: qa-page.php
*/
function qa_get_request_content()
{
$urlData = extract_request_url_data();
if($urlData['is_question'])
{
$userid = qa_get_logged_in_userid();
$questionid = $urlData['question_id'];
$question = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid));
$categoryBackPathFromDB = implode("/",array_reverse(explode("/",$question['categorybackpath'])));
if($categoryBackPathFromDB == $urlData['category_back_path']) //Valid URL
{
global $qa_request;
//set the global variable so that base function works correctly
$qa_request = implode('/',qa_request_parts(2));
}
}
return qa_get_request_content_base();
}
/*
Appends category back path to question URL in the format:
<root_category>/<sub_category>/<question-id>/<question-title>
Base: qa-base.php
*/
function qa_q_request($questionid, $title)
{
$path = qa_q_request_base($questionid, $title);
$userid=qa_get_logged_in_userid();
$question = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $questionid));
$explode_catBackpath = explode("/",$question['categorybackpath']);
$reverse = array_reverse($explode_catBackpath);
$categoryPath = implode("/",$reverse);
return $categoryPath.'/'. $path;
}
function extract_request_url_data(){
$requestparts = qa_request_parts();
$urlData = array(
'is_question' => false,
'index' => 0,
'question_id' => 0,
'category_back_path' => ''
);
for($i = 0; $i < count($requestparts); $i++){
if(is_numeric($requestparts[$i])){
$urlData['is_question'] = true;
$urlData['index'] = $i;
$urlData['question_id'] = intval($requestparts[$i]);
break;
}
}
if($urlData['is_question'] && $urlData['index'] > 0){
$urlData['category_back_path'] = implode('/', array_slice($requestparts, 0, $urlData['index']));
}
//var_dump($urlData);
return $urlData;
}
Regards,
Vaibhav