Forum Moderators: phranque

Message Too Old, No Replies

Need help with QUERY STRING redirect

         

vince786

10:59 pm on Feb 10, 2011 (gmt 0)

10+ Year Member



I am having trouble with a redirect abd I've setup the following rule. I would really appreciate some help! Without the query string of serial=100 the redirect works,

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/shopping/index\.jsp\ HTTP/ [NC]
RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^serial=100$
RewriteRule ^.*index\.jsp$ newhost:10080/shopping/index.jsp?serial=100 [R=301,L]


Thanks,

Vince

g1smd

12:04 am on Feb 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



THE_REQUEST is the literal HTTP request sent by the browser.

GET /somepath/somefile.ext?someparam=somevalue HTTP/1.1


Your pattern makes no provision for there to be any parameters contained in that request.

vince786

1:53 am on Feb 11, 2011 (gmt 0)

10+ Year Member



Thanks g1smd. I am quite confused now. So is it correct that I need to rewrite my rule as folows:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*/shopping/index\.jsp\ HTTP/ [NC]
RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^serial=100$
RewriteRule ^.*index\.jsp$ newhost:10080/shopping/index.jsp?serial=100 [R=301,L]

An existing rule that works is without the query string. So my task is to add a new rule that includes the query string. Based on what you said it looks like the first RewriteCond is not required. So I tried the fol:

RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^serial=100$
RewriteRule ^.*index\.jsp$ newhost:10080/shopping/index.jsp?serial=100 [R=301,L]

I am still having a problem. Is there a resource that you can point to that starts with the basics.

Thanks very much,

Vince

vince786

2:33 am on Feb 11, 2011 (gmt 0)

10+ Year Member



I looked at an example on the web and thought it should work for me but I am quite at a loss!

RewriteCond %{QUERY_STRING} ^pageId=0&start=0$
RewriteRule ^gallery/index.php gallery/index.php?pageId=117&start=0

Basically I have a url that needs to be rewritten which includes a new server name and port. :

htp://oldHost:8080/shop/index.jsp?name=abc
to
htp://newHost:10080/shop/index.jsp?name=abc

So I added the fol rule:

RewriteCond %{REQUEST_URI} ^.*/shop/index\.jsp\ HTTP/ [NC] <------------ IS THIS RewriteCond REDUNTANT
RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^name=abc$ <------------ Should there be a ? -> ^?name=abc$
RewriteRule ^.*index.jsp [newHost:10080...]

Apache does not like this. I would very much appreciate any thoughts re this.

Thanks very much!

jdMorgan

7:50 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One or the other of the first two rewriteconds should work, depending on what you're trying to do here. Delete or comment-out the one that you don't need.

RewriteCond %{SERVER_PORT} =8080
# RewriteCond %{HTTP_HOST} ^(www\.)?oldHost\.com\.?:8080$
RewriteCond %{QUERY_STRING} ^serial=100$
RewriteRule ^shop/index\.jsp$ http://newHost.com:10080/shop/index.jsp [R=301,L]

Delete your browser cache before testing any new server-side code.

Jim