Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to change to custom question URL?

+1 vote
asked Dec 12, 2016 in Q2A Core by questfor
Hi! I've recently installed Q2A on a website subdomain (e.g: http://www.domain.com/q2a/) and I have some problems trying to set up question URLs.

Despite the fact that there are some customization options in admin settings, I'm looking for another simple combination that's not available to select. What I'm looking for is for an estructure for questions like the following one:

instead of

Is there anyone else looking for the same?
I don't know if it's posible to do so but a URL without the question id between slashes would be perfect for something that I'm looking for.

I checked the htaccess and files like qa-base.php and many many more where it seems that q2a is doing something with URL but I haven't found anything. Hope you can help!

Thanks in advance
commented Dec 19, 2016 by arjunsuresh
You can of course make this work with custom modifications but do not think it is a good way as this would break some plugins or even core which reply on such a structure to get the postid.

3 Answers

0 votes
answered Dec 19, 2016 by questfor
Hi another time ;) Does anyone know how to solve this problem or has been in the same situation as me?
thx a lot for your help
0 votes
answered Dec 19, 2016 by sama55
Probably, such URLs will not be allowed. Because URL also changes when the question title is changed. At that time, the bookmarked link will be invalid. Incidentally, Q2A does not consider the title part when interpreting the URL.
+2 votes
answered Dec 20, 2016 by Scott

I think this should be doable with two main steps, using htaccess and overriding the request function.

Step 1: create an override plugin that overrides the function qa_q_request (from qa-base.php). You'll want mostly the same function but for the last line put

return $title . '-' . (int) $questionid;

Step 2: update your htaccess to handle the new format of URLs. Above the last RewriteRule I think you'll want something like this:

RewriteRule ^([^/]+)-([0-9]+)$ index.php?qa-rewrite=$2/$1&%{QUERY_STRING} [L]

Not sure if that's exactly right but should be similar.