useing / in url |
[eluser]Peerie_Pear[/eluser]
Hi all CI users I have a little problem. Im working on a simple webshop, and need to view my product details and i want to use the article /product id as reference My url is like this: http://www.mysite.com/webshop/detail/0/aabb4400 The 0 is used to open a certain menu entry, so not related to this post. The aabb4400 is the product /article id in this example. The url above will work. Problem comes when i have a product / article id with a / in it, then it says that the requested page can't be found. For example an url like: http://www.mysqite.com/webshop/detail/0/LS19HALESB/EDC will produce error: Not Found The requested URL /webshop/detail/0/LS19HALESB/EDC was not found on this server. the / is urlencoded to / Any idea how to solve this issue? I'm using the mod rewrite as it stands in the manual, using CI 1.5 atm
[eluser]Michael Wales[/eluser]
Probably not the most elegant option, but fairly simple: You could concatenate all segments after the second segment into a single variable, delimited by a /. Then search that string for 2 /s in a row and substr() off the last one - loop through this process until there are no double /s. Psuedo-code (assuming some products have up to 2 slashes): Code: // URL: domain.com/webshop/detail/0/LS19HALESB/EDC
[eluser]Peerie_Pear[/eluser]
Thanks, Looked like a solution at first, but the problem is that the 404 error (The requested URL /webshop/detail/0/LS19HALESB/EDC was not found on this server) is not a CI 404 error, so it looks more like an apache (rewrite) problem. (I will test it without rewrite later today) If i make a test script, that works with $_GET["productid"] vars it working fine (not in the ci dir, so not rewritten by apache) it accepts / in productid in the url without problems. What i don't get is that i urlencode a string, and that CI apears to see it as an urldecoded string. Im using CI 1.5 btw, if that makes any difference...
[eluser]louis w[/eluser]
I would not suggest using a / inside of a string like a product id, it only will cause confusion when passing it around in the url. Can you just do a string replace and change them to dashes or something and then do another replace before you query your db?
[eluser]Peerie_Pear[/eluser]
thats a possibility aswel, but maybe its better to use an unique integer id value to link the product details. I tought it would be nice to have the manufacturer product id in the url. but since they have "weird" characters in it every now and then, i should think of an other solution. Can anyone tell me waht CI / apache modrewrtie does with the URL that its not accepting urlencoded strings?
[eluser]Michael Wales[/eluser]
Yeah, I would definitely use your own unique ID and just store the manufacturer ID in the same row with the product's information. Hell, for SEO purposes it would be even better to make your links like: domain.com/products/gmc-denali-blue-widget I thin you could do a lot of work on your URLs, to be honest, webshop is a poor name for 'store', detail is unnecessary, I would love to see you get rid of the menu parameter (maybe use a session?), and the ID's could be made much more friendlier to use as a programmer.
[eluser]louis w[/eluser]
An easy way to have seo friendly urls and also an easy look up would be to use: domain.com/products/1234/cool-product Where cool-product is the product name, but you really ignore that and use the id before it to look up. The name is just there for google.
|
Welcome Guest, Not a member yet? Register Sign In |