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

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Apr 29: Q2A 1.5.2

Editing the default .htaccess file.... (how do I add 301 redirects correctly?)

+2 votes
I have a number of URLs indexed in Google as follows:
domain.com/25/ask  (when clicking it, it show a page with title: What is a cat)

So, I edited the end of .htaccess with this entry:
redirect 301 /25/ask http://www.domain.com/25/what-is-a-cat

However, when clicking or going to domain.com/25/ask, I'm redirected to:

http://domain.com/25/what-is-a-cat/?qa-rewrite=25/ask

My question...  Why is .htaccess adding ?QA-REWRITE=25/ask to the end of the URL and how do I remove that from these "hard coded 301 redirect settings?"
asked Oct 7, 2010 in Q2A Core by newguy

2 Answers

0 votes

Try adding [L] to the end of your redirect line (and put it first in the htaccess file). The [L] will tell the server to stop processing additional lines in the htaccess.

answered Oct 7, 2010 by DisgruntledGoat
Thanks for your help and response.  I'll be able to access/work on the site later, but are you saying to simply change the lines to:

redirect 301 /25/ask http://www.domain.com/25/what-is-a-cat [L] ?

Thanks again.
Putting the line first in the htaccess file make no difference.  Putting it first with a trailing [L] results in a 500 error message.

I'll have to read up on the proper syntax, any ideas?
I think I found the solution to do manual "301 style" redirects in the default .htaccess file.

On the third line (after the line that reads "RewriteEngine On")

Paste:

RewriteRule ^25/ask$ http://www.domain.com/25/what-is-a-cat [R=301,L]

Where 25/ask is the "bad url" and then you have the url you want the viewer to be forwarded to.  (The Redirect 301 method doesn't work because adding [L] after that line is improper syntax.)
0 votes

Below is a solution to do manual "301 style" redirects in the default .htaccess file.

On the third line (after the line that reads "RewriteEngine On")

Paste:

RewriteRule ^25/ask$ http://www.domain.com/25/what-is-a-cat [R=301,L]

Where 25/ask is the "bad url" and then you have the url you want the viewer to be forwarded to.  (The Redirect 301 method doesn't work because adding [L] after that line is improper syntax.)

I hope this is helpful to others.  If there's a better way to accomplish the above, please comment.  Thanks!

answered Oct 8, 2010 by newguy
Shouldn´t it be after the Rewrite Base line ?
I'm no .htaccess expert, but the solution above works for me.  I find if you add these manual redirects at the end of the file (or anywhere else) it doesn't function properly.  For example, the trailing L causes the .htaccess to "stop" after a rule is triggered.  If you were to put these manual rules at any other location (especially the bottom of the file) they may not even be called/work.