Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
971 views
in Q2A Core by
I have change the "Question title length in URLs" from 50 to zero now how can I do 301 redirect ?

Early my site URL was something like this :

https://example.com/50568/What-your-favorite-holiday

and now it is like:

https://example.com/50568/

I must do the 301 redirect for this change and how ?
by
+1
What makes you think you need to change anything?
by
because google already index my old url that's why ?
by
Then Google needs to re-index your site (which AFAIK they do periodically). No redirection on your side will change anything about that.
by
do you think I have taken wrong decision ?
But according to me shorter url is better
by
I believe so too, though that might be just me. I've never been a fan of putting post titles into URLs. And Q2A should automatically redirect example.com/123/foobar to example.com/123/ AFAICS. It does so on my own site, although I'm not running Apache, so the redirection is example.com/index.php/123/foobar to example.com/index.php/123/ in my case.

1 Answer

+1 vote
by
selected by
 
Best answer

Hello @Zeeshan,

@Ansgar Wiechers is right but if you'd like to go for it anyway, there are two ways of making it use a 301 redirect.

Method 1: Add the following line of code:

header("HTTP/1.1 301 Moved Permanently");

right above line 475 at qa-include/pages/question.php such that it looks like this:

// redirect if the current URL is incorrect
header("HTTP/1.1 301 Moved Permanently");
qa_redirect($q_request);

Method 2: Create a plugin, copy qa-include/pages/question.php over into it, add an override, override method `qa_get_request_content()` such that it'll point to the duplicate file (instead of the built-in one), and finally apply Method 1 to the duplicate file.


Tidbits

  • Where's that option?
    This is an administrator option available under `Admin``Viewing`. Look at the animation below:

Animation indication where the option 'Question title length in URLs' sits in

Is it a bug or a feature? Why do you think so? I'd like to hear your thoughts so please add your comments below.

Have a nice day.

by
Thank you so much brother
by
My pleasure! @Zeeshan
...