views:

1661

answers:

2

I have an htaccess redirect that needs to forward the query string to the new URL, but it's getting dropped after the redirect. Can someone tell me what's wrong?

RewriteRule ^services/agents.*$          https://services.example.com/agents/ [R=301,L,QSA]
+1  A: 

The same rule is working fine on my server. The problem should be something else. I added the same rule on my server and I get the following redirect

http://mysite.com/services/agents/foo?foo=bar => https://services.mysite.com/agents/?foo=bar

Please note that you don't need to add the QSA flag since the target doesn't include any query string. This article might contain some useful information to help you dealing with Htaccess and Query String.

Simone Carletti
I figured it out. The server I was redirecting to had its own redirect set up for /agents/ => /services/agents. Sigh..
Aaron
A: 

In general there is no need to explicitly append the query or use the QSA flag if you don’t specify a query for the substitution. But as you said your rule doesn’t work, try this:

RewriteRule ^services/agents.*$ https://services.example.com/agents/?%{QUERY_STRING} [R=301,L]
Gumbo