Jun Wei
Jun Wei

Reputation: 31

mod_rewrite: query string gets lost on rewrite

I have limited .htaccess knowledge and requires some help. I need to redirect all page request to www.newdomain.com except for www.olddomain/page.json but the query string get dropped when it redirect. how can i preserve it? thankyou very much!

Current code:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/page.json
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

Edit: Just to make it clear, i only need to stay on page.json on the old domain, lets say user request for www.olddomain.com/page1.json?session=gVgr30ExUlM i need to redirect to www.newdomain.com/page1.json?session=gVgr30ExUlM BUT when it is www.olddomain.com/page.json?=LKJHGF i need it to stay on that old domain and wont redirect is it possible?

Upvotes: 3

Views: 1533

Answers (2)

Michal M
Michal M

Reputation: 9480

You need to add [QSA] and optionally [NE] which should give you:

RewriteRule (.*) http://newdomain.com/$1 [QSA,NE,R=301,L]

Upvotes: 0

Fabian Schmengler
Fabian Schmengler

Reputation: 24576

Use the [QSA] flag ("query string append")

Upvotes: 3

Related Questions