0

Trying to redirect a URL with a query string to a subdomain, and can't get it to work.

The goal is to make www.example.com/services/json?method=views.get become old.example.com/services/json?method=views.get

I have in the .htaccess file:

RedirectMatch 301 ^www\.example\.com/services/json$ http://old.example.com/services/json$1

In Chrome, it just stays at the www domain.

In Firefox, it fails once, saying "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." But if I hit Try Again, it goes to the subdomain just fine.

This is infuriating, and any help is appreciated. I've tried several different patterns.

Thanks!

Also, there are double quotes in the query string. Is it possible to keep them without them becoming encoded to %2522?

1
  • The $1 should not be there. Commented Jan 27, 2012 at 19:19

2 Answers 2

4

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]
Sign up to request clarification or add additional context in comments.

1 Comment

Modified it to do what I needed to: RewriteCond %{HTTP_HOST} ^www\.example\.com/services/json$ [NC] RewriteRule ^(.*)$ old.example.com/$1 [R=301,L] And it doesn't work. It just stays on the www domain. So it doesn't work, seems not to affect anything.
1

I figured this out. Here is what I put to get it working:

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^services/json(.*)$ http://old.example.com/services/json$1 [NE,L,R=301]

Everything works perfectly now.

The NE tag at the end of the rule keeps the double quotes in the query string, as needed, and doesn't encode them.

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.