Results 1 to 9 of 9
  1. #1
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default updated site - need to figure out mod-rewrite stuff

    Ok I'm back with more regex stuff

    I have moved a sites shopping cart to a new system and need to make a few redirects

    But I am stuck

    so here goes

    The old store has 2 types of url that need replacing

    type 1

    Old Store
    h ttp://thesite.co.nz/index.php?page_ID=1&cat_ID=58
    New Store
    h ttp://thesite.co.nz/shop/index.php?main_page=index&cPath=858
    basically the category ID has 800 added to it

    I had a go at working it out but I can't figure out how to add 800 to the category variable in a rewrite does the below look like it will work? and I have a feeling I have cocked up regarding the & in the RewriteRule

    RewriteCond %{QUERY_STRING} ^page_ID=1&cat_ID\=([^&]+)$
    RewriteRule ^$ /shop/index.php?main_page=index&cPath=8%1 [R=301,L]


    Type 2
    and then there is this
    h ttp://thesite.co.nz/index.php?cat_ID=53&sub_ID=150&pg_ID=385&page_ID=2
    h ttp://thesite.co.nz/shop/index.php?main_page=index&cPath=853_650_385
    basically the category ID has 800 added to it as above
    and the sub_ID has 500 added to it

    I haven't done anything on this yet as I wanted to make sure I had the first one right

    Any help would be greatly appreciated
    Last edited by Morgenmuffel; 01-08-2007 at 10:19 PM.
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  2. #2
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    hmmm

    well i am a bit closer although i think i am beginning to understand more

    Code:
    RewriteCond %{QUERY_STRING} ^page_ID=1&cat_ID=([^/\.]+)?$
    RewriteRule ^index\.php$ shop/index\.php\?main_page=index&cPath=8$1 [L]
    The 2 problems i am having are

    1) The URL in the address bar is not being changed to the new one
    2) The category variable is not getting passed correctly as i keep landing in the new store (yay), but I am getting an invalid category, but as i am not seeing the URL i'm not sure whats up
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  3. #3
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    hmmm

    Ok another problem

    If I add in the [R=301] redirect code as below the URL changes

    RewriteCond %{QUERY_STRING} ^page_ID=1&cat_ID=([^/\.]+)?$
    RewriteRule ^index\.php$ sbo_shop/index\.php\?main_page=index&cPath=8$1 [R=301,L]
    and the rewrite redirect comes out as
    h ttp://www.site.com/home/ms/public_html/shop/index.php?main_page=index&cPath=8

    Which is possibly closer to being what i want, however i don't even end up at the shop i just get the obvious error page
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  4. #4
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    Semi Eureka

    Solved one problem, i was missing the forward slash in front of shop

    eg
    shop becomes /shop jeez how did I miss that

    RewriteCond %{QUERY_STRING} ^page_ID=1&cat_ID=([^/\.]+)?$
    RewriteRule ^index\.php$ /shop/index\.php\?main_page=index&cPath=8$1 [R=301,L]
    The passed through URL is coming through as
    h ttp://www.site.com/shop/index.php?main_page=index&cPath=8

    so the category variable (58 from the example in the firs post) is not being added to the end of the new URL should read cpath=858
    Last edited by Morgenmuffel; 02-08-2007 at 06:27 PM. Reason: Am I really sitting here talking to my self
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  5. #5
    Pedant and proud of it
    Join Date
    Dec 2004
    Location
    Christchurch
    Posts
    6,047

    Default Re: updated site - need to figure out mod-rewrite stuff

    Without getting into the horrible details of the regex stuff, you have a very common problem in your script. It's the sort of thing that will always bite you.

    If you have more than 100 items with numeric IDs, prefixing "8" to the ID will suddenly stop "adding 800". After "ID=899", you will get "ID=8100" (and at 8999..81000, etc). It's dangerous to use strings to perform arithmetic.

    Some Web sites had an interesting date on 1 Jan 2000. They had "1 Jan 19100". Same problem; lazy programmers.

  6. #6
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    Quote Originally Posted by Graham L View Post
    Without getting into the horrible details of the regex stuff, you have a very common problem in your script. It's the sort of thing that will always bite you.

    If you have more than 100 items with numeric IDs, prefixing "8" to the ID will suddenly stop "adding 800". After "ID=899", you will get "ID=8100" (and at 8999..81000, etc). It's dangerous to use strings to perform arithmetic.
    For the add 800 there will not be a problem as they were the primary categories on my site and the value range for them was 20 - 70 as the old store is closed there will never be anything higher and it will be fine

    However the main issue i am going to have is with my second string (Type 2 in the first post) as i added 500 to the old values unfortunately the old values ranged from 12 to 180 so the new values are 512 to 680, I think i'm screwed trying to deal with that especially since i have found this first URL so difficult

    I have two options
    1) somehow add 500 to the passed variable within the htaccess file (probably not even possible)
    2) count the number of character in the variable if it has 2 chars append a 5 on the front, if it has 3 send it to the parent category page

    However that is all academic if i don't figure out the first URL
    Last edited by Morgenmuffel; 02-08-2007 at 06:51 PM.
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  7. #7
    Pedant and proud of it
    Join Date
    Dec 2004
    Location
    Christchurch
    Posts
    6,047

    Default Re: updated site - need to figure out mod-rewrite stuff

    Such an editing script language will have a way to convert from string to numeric and back again, and arithmetic operators, surely. "type conversion" in the index?

  8. #8
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    Yay yippeee etc I have the first string working

    RewriteCond %{QUERY_STRING} ^page_ID=1&cat_ID=([^/\.]+)?$
    RewriteRule ^index\.php$ /sbo_shop/index\.php\?main_page=index&cPath=8%1 [R=301,L]
    I had to change the $1 to %1 because i had got the variable from the rewrite condition Not the rewrite rule
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

  9. #9
    morgenmuffel
    Join Date
    Dec 2004
    Location
    Putaruru
    Posts
    2,904

    Default Re: updated site - need to figure out mod-rewrite stuff

    Quote Originally Posted by Graham L View Post
    Such an editing script language will have a way to convert from string to numeric and back again, and arithmetic operators, surely. "type conversion" in the index?
    I hope so, But my brain has turned to mush i have spent the best part of the day figure out the first redirect the second one looks a heck of a lot harder
    Morgenmuffel - This word needs to be a part of the english language, in fact you should use it in everyday conversation

Similar Threads

  1. Replies: 1
    Last Post: 15-03-2008, 08:56 PM
  2. Stuff site always crash's Firefox?
    By beetle in forum PressF1
    Replies: 20
    Last Post: 10-07-2005, 02:24 PM
  3. Rewrite again to CD-R works
    By E.ric in forum PressF1
    Replies: 12
    Last Post: 05-09-2002, 11:49 PM
  4. Notified when a site is updated
    By Fred in forum PressF1
    Replies: 3
    Last Post: 19-08-2002, 04:44 PM
  5. Replies: 2
    Last Post: 02-01-2002, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •