Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
104 views
in Q2A Core by

301 Redirections

hello i need code when i  enter  http://yoursite.com/1234

change automatically to http://yoursite.com/1234/i-love-you   with last part

1 Answer

+2 votes
by

1. Create "my-override" folder under qa-plugin/.

2. Create plugin files under my-override folder.

metadata.json​


"name": "My Override", 
"description": "Customize Q2A functions", 
"version": "1.0", 
"date": "2017-04-22", 
"author": "PowerQA", 
"author_uri": "http://www.powerqa.org", 
"license": "GPLv2", 
"min_q2a": "1.5" 
}

qa-plugin.php​​

<?php 
/* 
Question2Answer by Gideon Greenspan and contributors 
http://www.question2answer.org/
File: qa-plugin/my-override/qa-plugin.php 
Description: Initiates My Override plugin

This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation; either version 2 
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php 
*/
/* 
Plugin Name: My Override 
Plugin URI: 
Plugin Description: Customize Q2A functions 
Plugin Version: 1.0 
Plugin Date: 2017-04-22
Plugin Author: PowerQA 
Plugin Author URI: http://www.powerqa.org/ 
Plugin License: GPLv2 
Plugin Minimum Question2Answer Version: 1.5 
Plugin Update Check URI: 
*/

if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser 
header('Location: ../../'); 
exit; 
}
qa_register_plugin_overrides('qa-my-overrides.php')

qa-my-overrides.php​

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

function qa_get_request_content() {
    if(is_numeric(qa_request_part(0)) && empty(qa_request_part(1))) {
        $post = qa_db_select_with_pending(qa_db_full_post_selectspec(qa_get_logged_in_userid(), qa_request_part(0)));
        $url = qa_q_path_html($post['postid'], $post['title']);
        qa_redirect_raw($url);
    }
    return qa_get_request_content_base();
}

3. Note

Create files in a text editor using UTF-8 encoding and ensure you do not add a BOM (byte order mark).

...