3

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]

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out. The server I was redirecting to had its own redirect set up for /agents/ => /services/agents. Sigh..
2

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.