| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 81602 | 2007-08-01 11:08:00 | updated site - need to figure out mod-rewrite stuff | Morgenmuffel (187) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 575084 | 2007-08-01 11:08:00 | 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 |
Morgenmuffel (187) | ||
| 575085 | 2007-08-02 06:48:00 | hmmm well i am a bit closer although i think i am beginning to understand more 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 (187) | ||
| 575086 | 2007-08-02 07:07:00 | 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 (187) | ||
| 575087 | 2007-08-02 07:26:00 | 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 |
Morgenmuffel (187) | ||
| 575088 | 2007-08-02 07:34:00 | 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. ;) |
Graham L (2) | ||
| 575089 | 2007-08-02 07:47:00 | 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 |
Morgenmuffel (187) | ||
| 575090 | 2007-08-02 08:01:00 | 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? | Graham L (2) | ||
| 575091 | 2007-08-02 08:08:00 | 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 (187) | ||
| 575092 | 2007-08-02 08:09:00 | 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 (187) | ||
| 1 | |||||