Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
692 views
in Q2A Core by
I am having trouble figuring out how to configure my .htaccess file for a 301 redirect as I would like to move my Q and A script from the root to /qna/ subdirectory. However, the issue is I would also like to use the root directory for my website.

In summary how do I code or can I code some kind of 301 redirect in the .htaccess file such that I don't bugger up my existing indexed pages and at the same time free up the root so that I can install my website??? Can use a regex with RedirectMatch to accomplish this? If so, can someone please help me with the expression?

Thanks

1 Answer

+1 vote
by

The question URLs are of the form /1234/question-title, so assuming you don't have pages on your main site that only consist of numbers, you can do something like:

RedirectMatch 301 ^/([0-9]+)/(.*)$ http://www.yoursite.com/qna/$1/$2

The other pages are probably not worth redirecting, but you can do the users and tags pages with this:

RedirectMatch 301 ^/user/(.*)$ http://www.yoursite.com/qna/user/$1
RedirectMatch 301 ^/tag/(.*)$ http://www.yoursite.com/qna/tag/$1

 

...