Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a 301 redirect to move from one system to another. I have the process nailed down that matches the old url to the new url and generates all the 301s for me but for the life of me I cannot get .htaccess to get the redirect to fire.

I have a feeling that it has to do with the fact that I have to use a query string in order to go between the two systems. Anyways here is what I have in my .htaccess file now:

RewriteEngine on

Options +FollowSymLinks

redirect 301 /cgi-bin/classifieds/classifieds.cgi?db=autos&website=FossilCars&language=&session_key=&search_and_display_db_button=on&results_format=long&db_id=46990&query=retrieval

Does anyone know what I could be doing wrong here? I have already disabled the cgi-bin directory in my Apache configuration (I know that because it's now loading our custom 404 page instead of the generic one).


Josh Pennington

share|improve this question
up vote 1 down vote accepted

Apparently Apache does not use the query string when determining a match for a URL redirect. The answer is to set a URL rewrite. Here is an example that worked for me:

# Redirect From 
# /cgi-bin/classifieds/classifieds.cgi?db=autos&website=FossilCars&language=&session_key=&search_and_display_db_button=on&results_format=long&db_id=46990&query=retrieval
# To
# /triumph/tr6/46990
RewriteCond %{REQUEST_URI} /cgi-bin/classifieds/classifieds.cgi$
RewriteCond %{QUERY_STRING} ^db=autos&website=FossilCars&language=&session_key=&search_and_display_db_button=on&results_format=long&db_id=46990&query=retrieval$
RewriteRule ^.*$ [L,R=301]

The ? at the end of the RewriteRule line drops the query string from the redirected URL.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.