Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 http://domain.com/triumph/tr6/46990

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).

Thanks

Josh Pennington

share|improve this question
add comment

1 Answer 1

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 ^.*$ http://example.com/triumph/tr6/46990? [L,R=301]

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

share|improve this answer
add comment

Your Answer

 
discard

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.