Forum Moderators: phranque

Message Too Old, No Replies

Redirect and keep unique URI data?

         

dfresh4130

3:27 am on Jul 16, 2009 (gmt 0)

10+ Year Member



I currently have an app that listens on a simple URI like www.ggg.com/abc and we're looking to change the root URI to something else like /123. I've just found out though that some of the traffic to this URL contains unique data after the URI like www.ggg.com/abc/getInfo.do?AAAA. Is it possible for apache to have a rewrite to where the root URI performs a redirect and then keeps the unique info after that URI? Ideally I'd like a rewrite of www.ggg.com/abc/getInfo.do?AAA to redirect to where the abc changes to 123 and keep all the data after that like www.ggg.com/123/getInfo.do?AAA. Sorry if this is simple, but maybe I just don't know what to search for since I haven't been able to find anything. Thanks

jdMorgan

3:40 am on Jul 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "unique data" following the question mark that you refer to is called the "query string," often composed of "name/value pairs" and accessed within scripts as "GET parameters."

You will be pleased to learn that passing query strings through redirects is Apache's default behavior. :)

Preserving the path info is simple enough as well, and is the default behavior of some of the redirect-related Apache directives. For those where it is not the default behavior, it's simple enough to do anyway.

Jim

dfresh4130

4:05 am on Jul 16, 2009 (gmt 0)

10+ Year Member



So would a simple rewrite like this work?

<VirtualHost *>
RewriteEngine On
RewriteRule ^/abc [ggg.com...] [R,L]
</VirtualHost>

dfresh4130

9:15 am on Jul 16, 2009 (gmt 0)

10+ Year Member



It may also help if I give a complete example of a URL with the dynamic data that's being passed.

[ggg.com...]

Basically I need to make sure everything stays the same after the abc and just have that change to 123. I tested with my example, but it seems to be just rewriting to the static URL of www.ggg.com/123 and cutting off the data after that.

jdMorgan

3:15 pm on Jul 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect you'll want to preserve the URL-path as well:

RewriteEngine on
RewriteRule ^/abc(/.*)?$ http://www.example.com/123$1 [R=301,L]

Jim

dfresh4130

8:22 pm on Jul 16, 2009 (gmt 0)

10+ Year Member



Works perfectly, thanks!