Question

I'm trying to accomplish some redirects as follows:

#Basic Rule Set
RewriteRule ^/path$ http://newhost.com/Page?pagename=form1000 [R=301]
RewriteRule ^/path/index.html$ http://newhost.com/Page?pagename=form1000 [R=301]

which work fine.

However, redirects with query strings in source and destination return me to the above destination url. For e.g.,

# Advanced  Rule Set
RewriteRule ^/path/index.html?var=foo$ http://newhost.com/Page?pagename=form1000?id=hello  [R=301]
RewriteRule ^/path/index.html?var=bar$ http://newhost.com/Page?pagename=form1000?id=byebye [R=301]
RewriteRule ^/path/index.html?var=xyz$ http://newhost.com/Page?pagename=form1000?id=world  [R=301]

all redirect to http://newhost.com/Page?pagename=form1000. I've tried a RewriteCond %{QUERY_STRING} ^var=(.*)$ [NC] and RewriteCond %{REQUEST_URI} ^/path/index.html [NC] preceding the above three rules, and still I'm redirected to http://newhost.com/Page?pagename=form1000. I've swaped the order of the Basic and Advanced rule sets, and all redirect to http://newhost.com/Page?pagename=form1000.

Any ideas on how I might get these rule sets to work? CentOS 6.x, Apache 2.2.

Was it helpful?

Solution

You may try this instead:

# Advanced  Rule Set
RewriteCond %{QUERY_STRING} var=foo [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=hello  [R=301,L,NC]

RewriteCond %{QUERY_STRING} var=bar [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=byebye [R=301,L,NC]

RewriteCond %{QUERY_STRING} var=xyz [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=world  [R=301,L,NC]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top