Forum Moderators: phranque

Message Too Old, No Replies

Redirect with query string in URL

         

jamie_g

8:20 pm on Oct 16, 2007 (gmt 0)

10+ Year Member



Hi gang,

Scenario:

* site has migrated from one shopping cart to another
* query string for individual products has changed, and now jumps out to another server
* product IDs are not the same from old cart to new cart

What I need to do:

Point old product URL
[mysite.com...]

To new product URL (on different server)
[newhost.com...]

Where do I start? I know I can't do a straight 301 Redirect because of the query string. From what I've read I need to use [QSA]? But can't find a working example. The book I'm reading talks about it (The Definitive Guide to Apache mod_rewrite), but I don't see a good example.

Cheers, Jamie

jdMorgan

11:45 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need to know the 'scale' of this project to give a good answer: Just how many old URLs do you have?

For small applications, a simple series of RewriteConds and RewriteRules can be used. For larger applications, your best bet is either a text lookup table, or a database query using RewriteMaps (in addition to one or a few RewriteConds and RewriteRules. The former solution is relatively simple, while the latter, though not dauinting, is certainly not trivial, and will require a small PERL script to do the database lookup and return the new URL and parameters.

Jim

jamie_g

11:52 am on Oct 17, 2007 (gmt 0)

10+ Year Member



Hi Jim,

Thank you for your response.

I have a total of 8 products that need to be updated.

With some additional digging I've found a similar post:

[webmasterworld.com...]

The example in the post above has this:

RewriteEngine on
RewriteCond %{query_string} ^p=78598870&more=1
RewriteRule /* http://example.com/archives/000124.php [R,L]

* {query_string}: Is this the start of the old URL with the string?
* What if I'm two directory levels deep to I append the static part of the URL before {query_string}

Again, thank you for your help.

Cheers, Jamie

[edited by: jdMorgan at 4:27 pm (utc) on Oct. 17, 2007]
[edit reason] example.com [/edit]

jdMorgan

4:32 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



QUERY_STRING is *only* the query string appended to the URL -- That is, the part after the "?"

Use the RewriteRule pattern to test the URL-path itself -- Everything after example.com/ and before the "?"


RewriteEngine on
RewriteCond %{QUERY_STRING} ^productid=1&cat=2&page=1
RewriteRule ^store/product\.php$ http://www.newhost.com/site/Detail?no=1 [R=301,L]

Jim

[edited by: jdMorgan at 4:34 pm (utc) on Oct. 17, 2007]

jamie_g

10:50 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



Hi again Jim,

Thank you for all your help!

Cheers, Jamie