Forum Moderators: phranque

Message Too Old, No Replies

htaccess Redirect for dynamic URL's

htaccess Redirect for dynamic URL's

         

cape

11:32 am on Feb 10, 2009 (gmt 0)

10+ Year Member



Hi

I need a redirect for ID items from a database. The server has been changed from ASP to PHP, along with a new directory system, and the old ASP addresses no longer exist.

I need to redirect:

http://example.com/Directory/search/dispBusiness.asp?BusID=00000
to
http://example.com/component/option,com_mtree/task,viewlink/link_id,00000/Itemid,32/

where 00000 is a variable ID number.

I've torn my hair out trying everything! Can anyone help with this please?

Thanks

[edited by: jdMorgan at 2:17 pm (utc) on Feb. 10, 2009]
[edit reason] please use example.com only [/edit]

wildbest

12:10 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Opsss... sorry you can't redirectmatch a query string

So it must be

RewriteEngine On

RewriteCond %{QUERY_STRING} ^BusID=([0-9]+)$
RewriteRule ^/?Directory/search/dispBusiness\.asp\?BusID=([0-9]+)$ http://example.com/component/option,com_mtree/task,viewlink/link_id,$1/Itemid,32/ [R=301,L]

[edited by: wildbest at 12:30 pm (utc) on Feb. 10, 2009]

[edited by: jdMorgan at 2:17 pm (utc) on Feb. 10, 2009]
[edit reason] example.com [/edit]

cape

12:21 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Thanks for your reply.
I am stil getting the following:

Not Found
The requested URL /Directory/search/dispBusiness.asp was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

wildbest

12:54 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Usually when a new .htaccess file is created,or an existing .htaccess file is deleted, however, these changes will not be seen until the htaccess cache is cleared. Depending on the hosting provider you're using this process may take place every hour or two.

jdMorgan

2:16 pm on Feb 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reason that RedirectMatch and the above mod_rewrite code won't work is that query strings are not part of a URL but rather data attached to that URL, to be passed to the resource *at* that URL. Therefore, neither RedirectMatch not RewriteRule can 'see' the query string.

Try:


RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^BusID=([0-9]+)$
RewriteRule ^/?Directory/search/dispBusiness\.as[b]p$[/b] http://example.com/component/option,com_mtree/task,viewlink/link_id[b],%1/[/b]Itemid,32[b]/?[/b] [R=301,L]

instead.

This assumes that the values of "option," "task," and "ItemID" are fixed values based only on the match with the requested URL, because they cannot be derived as variables from that requested URL. For example, the value of "ItemID" in the new URL will always be "32" because the the originally-requested URL carries only "LinkID" as a variable, and does not explicitly contain any information about the ItemID.

Jim

cape

2:25 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Thank you very, very much. That did it!
best wishes
Carl