Forum Moderators: phranque

Message Too Old, No Replies

redirect query string url to home page

redirect htaccess query string

         

emailrk

2:09 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



Hi All,

Need your help in reducting URL's with a query string to home page. I have bunch of URL's like this

http://www.example.com/dev/?id=1
http://www.example.com/dev/?id=2
and so on ...

and

http://www.example.com/test/?id=1
http://www.example.com/test/?id=2
and so on ...

I would like to redirect all those URL's to http://www.example.com

Can someone help/guide me please.

Thanks
Chris

jdMorgan

3:44 pm on Aug 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Chris,

Do you want to redirect *all* URLS with the "id=number" query string appended to "www.example.com/", or only those in the /dev and /test subdirectories?

And how about that id number -- Is it always a single digit, or might it be two or more? If so, do you want to redirect based on the number of digits, or redirect no matter how many digits are present?

It's best to be extremely specific before getting into any discussion of coding, because regular-expressions pattern-matching requires precision: Incomplete or bad requirements specification => bad code.

Jim

emailrk

3:51 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for your quick response.

Do you want to redirect *all* URLS with the "id=number" query string appended to "www.example.com/", or only those in the /dev and /test subdirectories?

>> Only the /dev/ and /test/ subdirectories

And how about that id number -- Is it always a single digit, or might it be two or more? If so, do you want to redirect based on the number of digits, or redirect no matter how many digits are present?

>> redirect no matter how many digits are present

Thank you,
Chris

jdMorgan

4:26 pm on Aug 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, so you need a RewriteCond to examine the %{QUERY_STRING} variable for a match to the pattern ^id=[0-9]+$ and a RewriteRule to match the URL-path-pattern ^(devŠtest)/$ and redirect to http://www.example.com/? (that trailing question mark is a token that will clear the query string) specifying [R=301,L] as the flags to invoke a 301-Moved Permanently redirect and to stop further mod_rewrite processing for this pass.

Referring to the resources cited in our Apache Forum Charter, try putting together a rule with that info, and be sure to post any questions back here.

You'll need to replace the broken pipe "Š" character in the RewriteRule pattern above with a solid pipe before trying to use it; Posting on this forum modifies the pipe characters.

Jim