Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule

dynamic url search to another url

         

ln031

1:58 pm on May 10, 2010 (gmt 0)

10+ Year Member



Hi Guys,

I'm new to an Apache RewriteRule, as I was trying to do the following but it doesn't work.

Redirect from
http://www.example.com/lbr_sports?action=go_generic_link&category=SPORTS&level=CLASS&key=110000037
to
http://sports.example.com/en-gb/Politics/Budget-SpecialsPolitics/Budget-Specials-t210002086

and

from
http://www.example.com/lbr_sports?action=go_type&category=SPECIALS&type_id=210003519
to
http://sports.example.com/en-gb/TV%2C-Film-and-Radio-c110000052

I'm trying to edit the rewrite module file as follow

RewriteCond %{QUERY_STRING} RewriteCond %{QUERY_STRING} ^lbr_sports(?)action=go_generic_link(&)category=SPORTS(&)level=CLASS(&)key=110000037
RewriteRule ^(.*)$ http://sports.example.com/en-gb/Politics/Budget-SpecialsPolitics/Budget-Specials-t210002086%4 [R=301,L]

RewriteCond %{QUERY_STRING} ^br_sports(?)action=go_type(&)category=SPECIALS(&)type_id=210003519&?$
RewriteRule ^(.*)$ http://sports.example.com/en-gb/TV%2C-Film-and-Radio-c110000052 [R=301,L]

Any help much appreciate it.

Thanks,
Peter

[edited by: jdMorgan at 6:17 pm (utc) on May 10, 2010]
[edit reason] example.com, disabled smilies in code [/edit]

jdMorgan

6:25 pm on May 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It appears that you've mixed the URL-path pattern with the query string pattern in the RewriteCond. Try:

# Redirect /lbr_sports?action=go_generic_link&category=SPORTS&level=CLASS&key=110000037 to
# http://sports.example.com/en-gb/Politics/Budget-SpecialsPolitics/Budget-Specials-t210002086
RewriteCond %{QUERY_STRING} ^action=go_generic_link&category=SPORTS&level=CLASS&key=110000037&?
RewriteRule ^lbr_sports$ http://sports.example.com/en-gb/Politics/Budget-SpecialsPolitics/Budget-Specials-t210002086%4 [R=301,L]
#
# Redirect /lbr_sports?action=go_type&category=SPECIALS&type_id=210003519 to
# http://sports.example.com/en-gb/TV%2C-Film-and-Radio-c110000052
RewriteCond %{QUERY_STRING} ^action=go_type&category=SPECIALS&type_id=210003519&?
RewriteRule ^lbr_sports$ http://sports.example.com/en-gb/TV%2C-Film-and-Radio-c110000052 [R=301,L]

Please see the resources cited in our Apache Forum Charter. Be aware that "guessing" at mod_rewrite code and regular-expressions patterns without consulting the documentation is highly dangerous.

Jim

ln031

9:24 am on May 11, 2010 (gmt 0)

10+ Year Member



Thanks for all your help Jim. I must be sleeping during the tested procedure, as I have it right first time without enter IP address into /etc/hosts for testing.

It's good to know that you are willing to share your expertise and much appreciate it.

Peter