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

I realize that the more distant from homepage the URLs are, the less Adsense ads are shown. You will feel that easier when you install Q2A in a sub-folder. It is because Q2A system adds an extra slash.

For example: mysite.com/folder/12345/why-do-birds-sing?

This is a three-slash URL.

Is there a way to reduce the slash? Like mysite.com/folder/why-do-birds-sing-12345 ?

I have seen websites which were developed from Q2A source code doing this. But I don't know how? An .htaccess tweak or something?

Edit: Though I can change the URL by overriding

function qa_q_request($questionid, $title)
{
    if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

    require_once QA_INCLUDE_DIR . 'app/options.php';
    require_once QA_INCLUDE_DIR . 'util/string.php';

    $title = qa_block_words_replace($title, qa_get_block_words_preg());
    $slug = qa_slugify($title, qa_opt('q_urls_remove_accents'), qa_opt('q_urls_title_length'));

//    return (int)$questionid . '/' . $slug;
return (int)$questionid . '-' . $slug;
}

But I don't know how to make the page loads with a new URL structure. Something need to be changed in here.

https://github.com/q2a/question2answer/blob/d9f19b6bac5489113fce8877b1d110baeb86fa44/qa-include/pages/question.php#L36

Edit 2:

It seems the real problem is from function qa_index_set_request() in https://github.com/q2a/question2answer/blob/d9f19b6bac5489113fce8877b1d110baeb86fa44/qa-include/qa-index.php#L55  . URLs without slash become unrecognizable. Hope one day, somebody will look into this.

closed with the note: Finally solved it! Not perfect but okay.
by
My question content actually did cover this. Q2A is built with slash-separated Url scheme. I created a function that deals with raw variable $_SERVER['REQUEST_URI']. Maybe a cultured PHP student can handle this nicely. I am not, don't even have a background in IT.

1 Answer

+1 vote
by

I currently have this structure: mysite.com/12345/why-do-birds-sing

I have to find a way how to do this: 

mysite.com/why-do-birds-sing-12345

by
How to change the standard link

`site.org/58020/how-to-replace-spa` to

`site.org/58020-how-to-replace-spa` on the site.

id/prettyurl to id-prettyurl
...